In Action

Php Toycode - Pushing element into an array

Simple example demonstrating how to push an element into an array.

Php in Action


forloop



Toycode

Php Code

Just cut-n-paste to reuse.

     
<?php
$one = "";
$two = "foo";
$three = "";
$four = "bar";

$procarr = array(); //create empty array

if (trim($one) != '')
{
	 array_push($procarr,$one);
}	
if (trim($two) != '')
{
	 array_push($procarr,$two);
}	 
if (trim($three) != '')
{
	 array_push($procarr,$three);
}	 
if (trim($four) != '')
{
	 array_push($procarr,$four);
}	 
 
$cnt = count($procarr);

for ($i=0;$i<$cnt; $i++)
{
	echo "\$procarr[" . $i . "]=" . $procarr[$i] . "
"; } ?>