473,382 Members | 1,784 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

array of array

I've to save in an array of array some values.

Problem: I don't know the size of the array before filling it.

I'd like something like

$bigarray = array():

then runnig the code I must create dinamically (I don't know how many) few
arrays in the bigarray;
$bigarray["X"] = array():
$bigarray["Y"] = array():

then fill those arrays with few unknow number of values.
array_push($bigarray["X"],$value1);
array_push($bigarray["X"],$value2);

array_push($bigarray["Y"],$value5);
....
but array_push doesn't manage it.

How to do so ?

Bob
Sep 29 '05 #1
4 1358
Bob Bedford wrote:
I've to save in an array of array some values.

Problem: I don't know the size of the array before filling it.

I'd like something like

$bigarray = array():

then runnig the code I must create dinamically (I don't know how
many) few arrays in the bigarray; $bigarray["X"] = array():
$bigarray["Y"] = array():

then fill those arrays with few unknow number of values.
array_push($bigarray["X"],$value1);
array_push($bigarray["X"],$value2);

array_push($bigarray["Y"],$value5);
...
but array_push doesn't manage it.

How to do so ?


$bigarray["X"][] = $value1;
$bigarray["X"][] = $value2;
....
$bigarray["Y"][] = $value5;

--
Kim André Akerĝ
- ki******@NOSPAMbetadome.com
(remove NOSPAM to contact me directly)
Sep 29 '05 #2
Bob Bedford wrote:
array_push($bigarray["Y"],$value5);
but array_push doesn't manage it.


Try $big_array['Y'][] = $value5;
In the manual it says "has the same effect" but maybe the implementation
is different? I don't know. It also says:

"Note: 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."

--
E. Dronkert
Sep 29 '05 #3
> $bigarray["X"][] = $value1;
$bigarray["X"][] = $value2;
...
$bigarray["Y"][] = $value5;

Does it create a new element in the $bigarray["X"] ?
I mean then I have
$bigarray["X"][0] == $value1;
$bigarray["X"][1] == $value2;

Bob

Sep 29 '05 #4
Bob Bedford wrote:
$bigarray["X"][] = $value1;
$bigarray["X"][] = $value2;
...
$bigarray["Y"][] = $value5;

Does it create a new element in the $bigarray["X"] ?
I mean then I have $bigarray["X"][0] == $value1;
$bigarray["X"][1] == $value2;


Yes. As mentioned in Ewoud Dronkert's reply, this is a better way of
doing it rather than using array_push(). Even the PHP manual mentions
this.

$bigarray[] = $value1;
=>
$bigarray[0] == $value1;

$bigarray[0][] = $value2;
=>
$bigarray[0][0] == $value2;

--
Kim André Akerĝ
- ki******@NOSPAMbetadome.com
(remove NOSPAM to contact me directly)
Sep 29 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Brian | last post by:
I'm diddlying with a script, and found some behavior I don't understand. Take this snippet: for ($i = 0; $i <= count($m); $i++) { array_shift($m); reset($m); }
2
by: Stormkid | last post by:
Hi Group I'm trying to figure out a way that I can take two (two dimensional) arrays and avShed and shed, and subtract the matching elements in shed from avShed I've pasted the arrays blow from a...
15
by: lawrence | last post by:
I wanted to test xml_parse_into_struct() so I took the example off of www.php.net and put this code up on a site: <?php $simple = <<<END <item>
8
by: vcardillo | last post by:
Hello all, Okay, I am having some troubles. What I am doing here is dealing with an employee hierarchy that is stored in an array. It looks like this: $employees = array( "user_id" => array(...
12
by: Sam Collett | last post by:
How do I remove an item with a specified value from an array? i.e. array values 1,2,2,5,7,12,15,21 remove 2 from array would return 1,5,7,12,15,21 (12 and 21 are NOT removed, duplicates are...
8
by: Mike S. Nowostawsky | last post by:
I tried using the "toUpperCase()" property to change the value of an array entity to uppercase BUT it tells me that the property is invalid. It seems that an array is not considered an object when...
58
by: jr | last post by:
Sorry for this very dumb question, but I've clearly got a long way to go! Can someone please help me pass an array into a function. Here's a starting point. void TheMainFunc() { // Body of...
104
by: Leszek | last post by:
Hi. Is it possible in javascript to operate on an array without knowing how mamy elements it has? What i want to do is sending an array to a script, and this script should add all values from...
7
by: Jim Carlock | last post by:
Looking for suggestions on how to handle bad words that might get passed in through $_GET variables. My first thoughts included using str_replace() to strip out such content, but then one ends...
17
by: =?Utf-8?B?U2hhcm9u?= | last post by:
Hi Gurus, I need to transfer a jagged array of byte by reference to unmanaged function, The unmanaged code should changed the values of the array, and when the unmanaged function returns I need...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.