PHP Cheat Sheet

--> ARRAY

$cars = array('honda','toyoda','hhh'); echo count($cars); <br> Result : 3
$cars = array('honda','toyoda','hhh'); print_r($cars); <br> Result : Array ( [0] => honda [1] => toyoda [2] => hhh )
$cars = array('honda','toyoda','hhh'); var_dump($cars); Result : array(3) { [0]=> string(5) "honda" [1]=> string(6) "toyoda" [2]=> string(3) "hhh" }
$people = array('Brad'=>35,'jhon'=>44); $ids = array(22 => 'brad', 55 =>'sam'); echo $people['Brad']; Result : 35 $people = array('Brad'=>35,'jhon'=>44); $ids = array(22 => 'brad', 55 =>'sam'); print_r($people); Result : Array ( [Brad] => 35 [jhon] => 44 )
array(2) { [22]=> string(4) "brad" [55]=> string(3) "sam" }

--> FOR LOOP

for($i = 5; $i <= 10;$i++){ echo $i; echo '<br>'; } Result :
5
6
7
8
9
10

--> WHILE LOOP

$j = 0; while($j < 10){ echo $j; echo '<br>'; $j++; } Result :
0
1
2
3
4
5
6
7
8
9

--> FOREACH

$people = array('brad','josh','will'); foreach($people as $person){ echo $person; echo '<br>'; } Result :
brad
josh
will
$peoples = array('brad'=>'brad@gmail.com','josh'=>'josh@gmail.com','will'=>'will@gmail.com'); foreach($peoples as $person => $email){ echo $person.' : '.$email; echo '<br>'; } Result :
brad : brad@gmail.com
josh : josh@gmail.com
will : will@gmail.com
Top Go to Next



main