Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Array problem

Status
Not open for further replies.

newdarkness

Programmer
Joined
Jan 31, 2005
Messages
4
Location
DK
Hello,
I got the following warning:
Code:
Warning:  First argument to array_push() needs to be an array in /[URL unfurl="true"]WWW/newcon-2/home/ypsilondownloads.de/www/eq.php[/URL] on line 52
On this array;
Code:
$eqpart = Array("L" => array (
				array ("+x0"),
				array ("+y0"),
				array ("+#0")),
		"R" => array (
				array ("+x0"),
				array ("+y0"),
				array ("+#0")));

And this Code:
Code:
		$Value = "-y1";
		$Type = valuePart($Value,"Type");	
		$eqside = 0;


		if($Type == "#") {
			array_push ($eqpart[$eqside][2],$Value);
			} elseif($Type == "x") {
			array_push ($eqpart[$eqside][0],$Value);
               		} elseif($Type == "y") {
			array_push ($eqpart[$eqside][1],$Value);
			}
		}
What the . are I'm doing wrong?
 
The array_push is probably too much overhead. Why don't you just add it using:
Code:
$eqpartp[$eqside][2][] = $Value;
PHP Manual:
If you use array_push() to add one element to the array it's better to use $array[] = because in that way there is no overhead of calling a function.
 
I need to include multiple arrays and sort those into the sub arrays - I'm not sure if $eqpartp[$eqside][2][] = $Value; will work multiple times without deleting the old array.

Also it said that $eqpart[$eqside][1] wasn't an array, thats what I am wondering about
 
$eqpartp[$eqside][2][] = $Value; will work multiple times. It just adds an element to the end of the array. Just like array_push.

Validate your assumption that $eqpart[$eqside][1] is an array by using is_array($eqpart[$eqside][1]);
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top