Php Toycode - Pushing element into an array

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

Php in Action


Php Code

Just cut-n-paste to reuse.

$one = "";
$two = "foo";
$three = "";
$four = "bar";

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

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

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

If you find this site useful and are a book buyer/reader...

Abe Books is one of my affiliates. I only use affiliates that I also purchase products from. I love Abe books. I have purchased many books from them originally cost $40 to $60 for as little as $5 to $10 dollars including shipping costs.

By accessing Abe books and clicking on one of my links I receive a small commission on your purchase that helps pay for this site. You pay no more for your books than if you accessed their site directly. Thanks for your support.

Click on icon to find books on Php at Abe Books...

The Following are a list of Php books I own

  • PHP Hacks: Tips & Tools for Creating Dynamic Web Sites by Jack D Herrington
  • PHP Cookbook by David Sklar; Adam Trachtenberg
  • Php: Your Visual Blueprint for Creating Open Source, Server-Side Content
  • Php In Action by Dagfinn Reiersol
  • Php 5 Objects, Patterns, and Practice

A few notes. Already having a rich programming background when I set out to learn Php I found the Visual Blueprint book invaluable. I was literally able to get up to speed on Php over a weekend. Of course it took many months of working in that language to really feel proficient.

Having already had a decent background in Object Oriented Programming in Java I found the two books "Php in Action" and "Php 5 Objects..." very well written and informative. I think they are written by folks with "real world" experience on the subject.

Free Shipping 125x125

75% of your donation

goes to charity.