-2

code:

<?php foreach($posts as $post) {

echo $post['name'] 
};
?>

Result : 100 value I want to print 10 values only How that?

1
  • 1
    100 values from database? If so, why you taking 100 result? Just limit to 10 result in query will fix your problem right? Commented Mar 11, 2019 at 11:39

1 Answer 1

0

Try like this

foreach($posts as $key => $post) {
  echo $post['name']; 

  //It will execute only ten times
  if($key == 9){
     break;
  }
}
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.