473,503 Members | 1,715 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2177

"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
2757
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
575
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
5155
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
3463
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
55526
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
10198
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
10046
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
16852
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
3166
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
7211
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
7203
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7087
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7281
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7334
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6993
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5579
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
3156
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1514
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
383
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.