473,320 Members | 1,856 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,320 software developers and data experts.

array of...array....

I've this structure in a XML file:
Type
Model
Detail
Datas
Datas
Datas
Datas
/Detail
Detail
Datas
Datas
Datas
/Detail
/Model
/Type

I've parsed all the stuff, by putting everything in an array.

Now, I've a problem as I must use datas in "Detail" tag every time they are
processed, but I must first process datas in Model, so I have to wait until
Model tag is closed.

For now I put everything in an array called $datas (where I store the couple
key/value). How can I do to create, at a certain point, a new array for
storing the Detail array (in order to have an array for every Detail that
may occur, as this isn't a fixed number of Details ?)

Thanks for helping.
Jul 17 '05 #1
8 2169

"Bob Bedford" <be******@YouKnowWhatToDoHerehotmail.com> wrote in message
news:40***********************@news.sunrise.ch...
I've this structure in a XML file:
Type
Model
Detail
Datas
Datas
Datas
Datas
/Detail
Detail
Datas
Datas
Datas
/Detail
/Model
/Type

I've parsed all the stuff, by putting everything in an array.

Now, I've a problem as I must use datas in "Detail" tag every time they are processed, but I must first process datas in Model, so I have to wait until Model tag is closed.

For now I put everything in an array called $datas (where I store the couple key/value). How can I do to create, at a certain point, a new array for
storing the Detail array (in order to have an array for every Detail that
may occur, as this isn't a fixed number of Details ?)

Thanks for helping.


Been to http://uk2.php.net/manual/en/ref.xml.php yet? XML parsers are your
friend.

Garp
Jul 17 '05 #2
Just create a new array for an array data :

like this

$data["Model1"]["Detail1"] = array("Datas1", "Datas2", "Datas3");

Savut

"Bob Bedford" <be******@YouKnowWhatToDoHerehotmail.com> wrote in message
news:40***********************@news.sunrise.ch...
I've this structure in a XML file:
Type
Model
Detail
Datas
Datas
Datas
Datas
/Detail
Detail
Datas
Datas
Datas
/Detail
/Model
/Type

I've parsed all the stuff, by putting everything in an array.

Now, I've a problem as I must use datas in "Detail" tag every time they
are
processed, but I must first process datas in Model, so I have to wait
until
Model tag is closed.

For now I put everything in an array called $datas (where I store the
couple
key/value). How can I do to create, at a certain point, a new array for
storing the Detail array (in order to have an array for every Detail that
may occur, as this isn't a fixed number of Details ?)

Thanks for helping.


Jul 17 '05 #3
> Been to http://uk2.php.net/manual/en/ref.xml.php yet? XML parsers are your
friend.


It's what I've done until now. My message tell that I've already passed this
stage. I have already parsed the XML file (with the help of examples from
php.net). The problem comes while using arrays.

Thanks anyway for your help.
Jul 17 '05 #4
"Savut" <we***@hotmail.com> a écrit dans le message de
news:wB**************@news20.bellglobal.com...
Just create a new array for an array data :

like this

$data["Model1"]["Detail1"] = array("Datas1", "Datas2", "Datas3");

Savut

Thanks, Savut, exactly the help I wanted !

One more question:
As you can guess, I'm not so confortable with arrays....so, how can I then
show all datas since sometimes Detail1 can be a value and other it can be an
array:

Like in pseudo-code
for every value of $data
if $data[value] is an array
for every Avalue of $data[value]
echo("$data[value][AValue][Key] -
$data[value][AValue][Value]<br>");
else
echo(echo("$data[value][Key] - $data[value][Value]<br>");

How can I do this ?

BoB
Jul 17 '05 #5
here come is_array($data[x][y]);

Savut
http://www.savut.com

"Bob Bedford" <be******@YouKnowWhatToDoHerehotmail.com> wrote in message
news:40***********************@news.sunrise.ch...
"Savut" <we***@hotmail.com> a écrit dans le message de
news:wB**************@news20.bellglobal.com...
Just create a new array for an array data :

like this

$data["Model1"]["Detail1"] = array("Datas1", "Datas2", "Datas3");

Savut

Thanks, Savut, exactly the help I wanted !

One more question:
As you can guess, I'm not so confortable with arrays....so, how can I then
show all datas since sometimes Detail1 can be a value and other it can be
an
array:

Like in pseudo-code
for every value of $data
if $data[value] is an array
for every Avalue of $data[value]
echo("$data[value][AValue][Key] -
$data[value][AValue][Value]<br>");
else
echo(echo("$data[value][Key] - $data[value][Value]<br>");

How can I do this ?

BoB


Jul 17 '05 #6
Thanks Savut,

In fact I'm stuck before this. I'll tell you the tree and then maybe you can
help me:
Take back the example:
/**************************/
Type
SomeDatas
SomeDatas
Model (array)
Mod0Datas
Mod1Datas
Detail (array)
Datas
Datas
Datas
Datas
/Detail
Detail (array)
Datas
Datas
Datas
/Detail
/Model
Brand (array)
Brand0Datas
Brand1Datas
Detail (array)
Datas
Datas
/Detail
Detail (array)
Datas
Datas
Datas
/Detail
/Brand
/Type
/**************************/
So I create the $data array for storing everyting in Type.
function startElement($parser, $name, $attrs)
....
switch($name){
case 'Type':
$datas["TAG"] = $name;
break;
case 'Model': //or 'Brand'
$actualarray = $name;
$datas[$actualarray] = array(); //create an array for Model or Brand
elements
break;
case 'Datas':
$datasindex = count($datas[$actualarray]);
$datas[$actualarray][$datasindex] = $name;

here I'm stuck !!!!
- $datas is the "Mother" array, that stores everything
- when I encounter the word "Model" or "Brand" in the XML file, I've to
create an array (empty for now).
- Until I encounter the closing /Model or /Brand, I've to put everything in
the $datas["Model"] array as long as they are datas.
in the $datas["Model"] or $datas["Brand"] array, I've to create an other
array as soon as I encounter the word "Detail" for storing the Detail's
datas, and then fill the $datas["Model"]["Detail"] until I encounter the
/Detail word.

My question is: How do I create such arrays on the fly (look the
startElement for what I mean) and what should I keep for pointers...I've to
keep indexes, as I will create an array of array of array, and I will then
be able to walk trough each element. (this code would also be greately
appreciated...)
I've never worked with PHP arrays before, this is the first time I need
them, and it's quite difficult as a starting point !!!!

Thank you !!!!

Best regards.

BoB
Jul 17 '05 #7

"Bob Bedford" <be******@YouKnowWhatToDoHerehotmail.com> wrote in message
news:40***********************@news.sunrise.ch...
Been to http://uk2.php.net/manual/en/ref.xml.php yet? XML parsers are your friend.
It's what I've done until now. My message tell that I've already passed

this stage. I have already parsed the XML file (with the help of examples from
php.net). The problem comes while using arrays.

Thanks anyway for your help.


Ah, I didn't know that's what you meant by parsed. Glad you got the help you
wanted in the end though.

Garp
Jul 17 '05 #8
Type
SomeDatas
SomeDatas
Model (array)
Mod0Datas
Mod1Datas
Detail (array)
Datas
Datas
Datas
Datas
/Detail
Detail (array)
Datas
Datas
Datas
/Detail
/Model
Brand (array)
Brand0Datas
Brand1Datas
Detail (array) --> $BrandDetail[0]
Datas
Datas
/Detail
Detail (array) --> $BrandDetail[1]
Datas
Datas
Datas
/Detail
/Brand
/Type
I suggest you to use xpath so you can navigate inside an xml document more
easily :
Here a simple preview of what he can do.
$domxml = new DomDocument("yourxmlfile.xml");
$xpath = new DomXPath($domxml);
$BrandDetail = $xpath->query("/Type/Brand/Detail");
foreach($BrandDetail as $value) {
$datas["Brand"]["Detail"][] = $value; //[] is used for auto increment
the array
}

But this work only on PHP5 as I know
here some exemple http://www.zend.com/php5/articles/php5-xmlphp.php

If not, then use domxml then navigate inside with has_child_nodes() and
node_name() and node_value() all with foreach() loop.
You can check this for exemple and tutorial, http://ca3.php.net/domxml.

This is very long but worth to learn it.

Hope this help

Savut
http://www.savut.com
Jul 17 '05 #9

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...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
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: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
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...

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.