because we are on the internet.

Use of for each funcation in php

 Foreach (array_expression as $value){

statement;

}

Foreach (array_expression as $key => $value){

statement;

}

for example

<?php

$arr = array(2,3,4,5) ;

foreach($arr as &$value){

$value = $value * 2;

}

//$arr now is array(4,6,8,10)

unset($value);//break the reference with the last element

//warning Reference of a $value and the last array element remain even after the foreach loop.It is recommended to destroy it by unset().

?>

<?php

$arr = array(”apply “,”orange”,”banana”);

reset($arr); //Set the internal pointer of an array to its first element

foreach($arr as $key => $value){

echo “Key:$key;Value:$value<br />\n”;

}

?>

Leave a comment

You must be logged in to post a comment.

 

About Author

Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Vestibulum at arcu. Integer et risus. Morbi id tellus. Integer felis. Mauris malesuada, turpis vitae facilisis euismod, dui arcu adipiscing sem, eu vulputate leo ante in lacus. Sed porta accumsan lectus. Aenean ac sem. In consequat tempus velit. Phasellus leo enim, adipiscing a, egestas nec, pretium ut, pede. Mauris sollicitudin diam et mauris. Sed quis enim vel augue egestas lobortis. Etiam tempus ipsum vel neque.