473,659 Members | 2,680 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 2189

"Bob Bedford" <be******@YouKn owWhatToDoHereh otmail.com> wrote in message
news:40******** *************** @news.sunrise.c h...
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******@YouKn owWhatToDoHereh otmail.com> wrote in message
news:40******** *************** @news.sunrise.c h...
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.b ellglobal.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("$dat a[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******@YouKn owWhatToDoHereh otmail.com> wrote in message
news:40******** *************** @news.sunrise.c h...
"Savut" <we***@hotmail. com> a écrit dans le message de
news:wB******** ******@news20.b ellglobal.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("$dat a[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($p arser, $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******@YouKn owWhatToDoHereh otmail.com> wrote in message
news:40******** *************** @news.sunrise.c h...
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("yo urxmlfile.xml") ;
$xpath = new DomXPath($domxm l);
$BrandDetail = $xpath->query("/Type/Brand/Detail");
foreach($BrandD etail 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
2779
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 print_r cmd any suggestions would be great. Thanks much Todd //avShed array Array ( => Array ( => 1 => 08:00 ) => Array ( => 1 => 08:05 ) => Array ( => 1 => 08:10 ) => Array ( => 1 => 08:15 ) => Array ( => 1 => 08:20 ) => Array...
15
5178
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
3474
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( "name", "title", "reports to user id", "start date in the format: mm/dd/yyyy" ) ); How can I display this hierarchy in simple nested <li> tags in the most
12
55548
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 also removed) So far I have (val is value, ar is array, returns new array):
8
10218
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 it is assigned a text literal?? HOW can I change the array value to upper case then? What other method exists for arrays? Ex: var GridArrayName1 = new Array(); GridArrayName1 = new Array ('test-value'); GridArrayName1 = GridArrayName1...
58
10121
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 code... TCHAR myArray; DoStuff(myArray);
104
16929
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 that array Could you show me a little example how to do this? Thanks.
7
3191
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 up looking for characters that wrap around the stripped characters and it ends up as a recursive ordeal that fails to identify a poorly constructed $_GET variable (when someone hand-types the item into the line and makes a simple typing error).
17
7239
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 to show the array data to the end user. Can I do that? How?
0
8427
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8330
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8850
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8746
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8626
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7355
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6178
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4175
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2749
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 we have to send another system

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.