Difference between revisions of "PHP - Adding values to an array"

From MyWiki
Jump to: navigation, search
(Created page with "<source lang="php"> <?php $stack = array("orange", "banana"); array_push($stack, "apple", "raspberry"); print_r($stack); ?> </source>")
 
 
(2 intermediate revisions by the same user not shown)
Line 4: Line 4:
 
$stack = array("orange", "banana");
 
$stack = array("orange", "banana");
 
array_push($stack, "apple", "raspberry");
 
array_push($stack, "apple", "raspberry");
 +
print_r($stack);
 +
?>
 +
</source>
 +
print_r prints a variable in human readable format<br>
 +
Popping the last item of an array
 +
<source lang="php">
 +
 +
<?php
 +
$stack = array("orange", "banana", "apple", "raspberry");
 +
$fruit = array_pop($stack);
 
print_r($stack);
 
print_r($stack);
 
?>
 
?>
 
</source>
 
</source>

Latest revision as of 12:55, 4 April 2019

<?php
$stack = array("orange", "banana");
array_push($stack, "apple", "raspberry");
print_r($stack);
?>

print_r prints a variable in human readable format
Popping the last item of an array

<?php
$stack = array("orange", "banana", "apple", "raspberry");
$fruit = array_pop($stack);
print_r($stack);
?>