개발관련/PHP
[PHP]Array Functions
파노카페
2012. 4. 20. 15:12
Array Functions
"; // shifts first element out of an array // and returns it. $a = array_shift($numbers); echo "a:" . $a ."
"; print_r($numbers); echo "
"; // prepends an element to an array, // returns the element count. $b = array_unshift($numbers, 'first'); echo "b: ". $b ."
"; print_r($numbers); echo "
"; echo "
"; // pops last element out of an array // and returns it. $a = array_pop($numbers); echo "a: " . $a ."
"; print_r($numbers); echo "
"; // pushes an element onto the end of an array, // returns the element count. $b = array_push($numbers, 'last'); echo "b: ". $b ."
"; print_r($numbers); echo "
"; ?> Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 [4] => 5 [5] => 6 )
a:1
Array ( [0] => 2 [1] => 3 [2] => 4 [3] => 5 [4] => 6 )
b: 6
Array ( [0] => first [1] => 2 [2] => 3 [3] => 4 [4] => 5 [5] => 6 )
a: 6
Array ( [0] => first [1] => 2 [2] => 3 [3] => 4 [4] => 5 )
b: 6
Array ( [0] => first [1] => 2 [2] => 3 [3] => 4 [4] => 5 [5] => last )