Answers for "how to count foreach loop in php"

PHP
9

foreach loop array php

foreach (array as $value){ 
  //code to be executed; 
  print("value : $value");
} 

foreach (array as  $key => $value){ 
  //code to be executed; 
  print("key[$key] => $value");
}
Posted by: Guest on April-12-2020
0

php foreach count rows

<?php

$count = 0;

foreach( $names as $name){

$count = $count + 1;

echo  "<td>".$count. "</td>

      "<td>".$name. "</td>";
}

echo $count;

?>
Posted by: Guest on February-16-2021
0

php wpdb foreach

get_header();
function get_records()
{
	//$con=connectsql();
	$records=$wpdb->query("SELECT * FROM $wpdb->posts WHERE post_type = 'elements' AND post_status = 'publish'");
	$all=array();
	while($data=$records->fetch_assoc())
	{
		$all[]=$data;
	}
	return $all;
}
Posted by: Guest on July-01-2020

Browse Popular Code Answers by Language