MemoryRefresh!

Stacks



Questions Answers 0%

Pages   0 from 51
Questions   0 from 84

Reset



array_push() - add at end
<?php // Example 1 $arr = array(); array_push($arr, 'bar', 'baz'); print_r($arr); // Array ( [0] => bar [1] => baz ) // Example 2 $arr[] = 'foo'; // when only one value if being pushed // faster than array_push (no function call) array_pop() - extract last element
<?php $arr = array('bar', 'baz'); $lastIn = array_pop($arr); var_dump($lastIn, $arr); // string(3) "baz" array(1) { [0]=> string(3) "bar" } array_shift() - remove first
<?php $arr = array('bar', 'baz'); $firstElement = array_shift($arr); //print_r($arr); // Array ( [0] => baz ) array_unshift() - add to begining
<?php $arr = array('baz'); array_unshift($arr, 'foo'); print_r($arr); // Array ( [0] => foo [1] => baz )
Questions

Related pages

Basics !
Operations !
Create !
Key-value !
Search !
Modify !
Pointer !
Sort !
Stacks !
Randomize !
Storage !


0% 100%
 
 
0 pages 51 pages
1) Remove the first element of an array





2) Add element to the begining of an array





3) Add element at the end of an array





4) Extract the last element of an array




Last Review: n/a   Passed: n/a   Reviews: n/a   Next Review: n/a  


array_push() - add at end
<?php // Example 1 $arr = array(); array_push($arr, 'bar', 'baz'); print_r($arr); // Array ( [0] => bar [1] => baz ) // Example 2 $arr[] = 'foo'; // when only one value if being pushed // faster than array_push (no function call) array_pop() - extract last element
<?php $arr = array('bar', 'baz'); $lastIn = array_pop($arr); var_dump($lastIn, $arr); // string(3) "baz" array(1) { [0]=> string(3) "bar" } array_shift() - remove first
<?php $arr = array('bar', 'baz'); $firstElement = array_shift($arr); //print_r($arr); // Array ( [0] => baz ) array_unshift() - add to begining
<?php $arr = array('baz'); array_unshift($arr, 'foo'); print_r($arr); // Array ( [0] => foo [1] => baz )



More from Php

Basics
Variables
Operators
Function
Array
String
Streams
Uncategorized


More from Programming

Php
jQuery




Powered by minte9.com