Printing all elements in an array

In php it may sometimes be important to print all of the elements contained inside of an array. In most instances you need to print them out forwards, starting with the element stored in the first array key, but sometimes you may need to print out the contents backwards. This process can be tricky and hard to understand for a lot of people so I tried to simplify it by making a function that will print out all the elements for you. Here it is:

function printAllArray($name,$action){
if($action == “foreward” || $action == NULL || $action == “”){
$amountIn = count($name);
for($x = 0; $x <= $amountIn;$x++){
print($name[$x]);
}
}
if($action == “backward”){
$amountIn = count($name);
for($x = $amountIn; $x >= 0;$x–){
print($name[$x]);
}
}
}


Read More...
Recently