Answers for "for next php array"

PHP
2

php for array key value

<?php
$array = array(1=>"apple",2=>"Orange",3=>"Banana");

foreach($array as $key => $value){
	echo "The value for " . $key . " is " . $value;
}
/*The value for 1 is apple
The value for 2 is Orange
The value for 3 is Banana

$array = [1 => "apple", 2 => "Orange", 3 => "Banana"    
    Is also valid
];*/  
?>
Posted by: Guest on February-01-2021
1

php loop array

<?php
$arr = array(1, 2, 3, 4);
foreach ($arr as &$value) {
    $value = $value * 2;
}
// $arr is now array(2, 4, 6, 8)
unset($value); // break the reference with the last element
?>
Posted by: Guest on April-28-2020

Browse Popular Code Answers by Language