Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
  Advanced Search
  HOME    TRACKER    PHP






SuperbHosting.net have generously sponsored dedicated servers to ensure a reliable and scalable dedicated hosting solution for BigResource.com.





Create Nested Array


i have a flat array with values like:

array[0] = "/fol1_level1"
array[1] = "/fol1_level1/fol1_level2"
array[2] = "/fol1_level1/fol1_level2/fol1_level3"
array[3] = "/fol2_level1"
array[4] = "/fol2_level1/fol2_level2"

...
i am trying to convert this array in to a nested one by using some kind of recursive logic that nests all related values for example: Code:




View Complete Forum Thread with Replies
Sponsored Links:

Related Messages:
Nested Associativee Array And Create The Object Dynamically
With PHP 4, is there a way to convert an associative array to an object?

For example, suppose I have the following arrays inside a nested associative
array ($nestedAA):

$AA1['field1'] = 'fieldValue1'

$AA2['field2'] = 'fieldValue2'

$nestedAA['AA1'] = $AA1;
$nestedAA['AA2'] = $AA2;

I would like to take $nestedAA and convert it to an object called

$nestedObject with properties I could access like this:

echo $nestedObject->AA1->field1; # This would print 'fieldValue1'
echo $nestedObject->AA2->field2; # This would print 'fieldValue2'

How can I do this? Note, I would like a conversion method that I could use with any nested associativee array and create the object dynamically (at runtime).

View Replies !   View Related
Nested MySQL Queries Create Issue With Validity Of Result Index?
I am iterating through a result set to generate a second set of queries but
no matter what I do I get the error

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result
resource

even though if I echo the query to the browser and cut and paste it into the
command line I get valid results.

Do I have to store the first result in an array before doing the second set?

while ($i < mysql_num_rows($result)) {
$PIDs[$id]['ClientName'] = $client;
$PIDs[$id]['ProjectName'] = mysql_result($result, $i, 'Name');
$PIDs[$id]['PID'] = mysql_result($result, $i, 'PID');
$thisPID = $PIDs[$id]['PID'];
$PIDresult = ("SELECT * from hours WHERE PID = '$thisPID'") or
die(mysql_error());
$j=0;
while ($j < mysql_num_rows($PIDresult)) {
$PIDs[$id]['PID']['Comments'] = mysql_result($PIDresult, $j,
'Comments');
$j++;
}
$i++;
}
}

View Replies !   View Related
Looping Through Nested Array
I parse through a xml file and create an array of the data. I now need to loop through all the nested arrays but I'm unsure of how to do this. Code:

View Replies !   View Related
Tree Traversal => Nested Array
'm exploring what DB-model for storing hierarchical data will suit my application best. As far as I can see there are two options: the adjency list model and the tree traversal model. The first one is pretty clear to me, and with it I'm able to get the entire tree or a portion of it into a nested array for further processing.

However, somehow the tree traversal method intrigues me and I want to see if it will fit my needs. So far my first major obstacle is to extract the data from the DB as a nested array, which I can pass on to my gui-class. My testing db looks like this now:

id|title|lft|rgt
1|root|1|10
2|item1|2|3
3|item2|4|9
4|item2.1|5|6
5|item2.2|7|8

Can anyone give me some pointers on how to process this?

View Replies !   View Related
Extracting Key & Its Value Form Nested Array
I have a huge nested array. How do i extract the key and its corresponding value from it.

FYI: the array was generated using xml_parse_into_struct, but I am not reading the entire XML file at once, only one tag.

View Replies !   View Related
Nested Array Loop Problem
I am trying to retrieve some records from a MySQL table and redisplay them. The data in list form looks like this: Code:

View Replies !   View Related
Trying To Compare Array Values To A Value, Then Create Boolean Array
I have an array that returns data like this (see array below) The array[0] contains all the votes for one story as well as information that pertains to that vote, and the array[1] contains vote information for another story. What I need to do is check is a user_id stored in a session, is in the array, and then create a boolean array from that.

For example, here I want to check if the user_id is featured in the first set of data, let's say my user_id is 74. Ok, so it is in the first set of data, so we set the boolean variable to true. Next I need to search the second data field for my user_id, 73. It is not featured here so the value in my array is set to 0.

I need an array that returns values either 1, for true, your user_id was found in the table, or false, for your user_id was not featured in the table. They need to be in order of the story too. I'm having trouble one comparing the two variables against eachother, since the array is very deep, and two, creating the array on the fly. Code:

View Replies !   View Related
Create Array From Members Of An Array Of Objects
I have the following situation:

$list[] is an array of MyElement objects.

MyElement has two members: MyElement->member1; MyElement->member2;

What I want is to get the following:

$newlist[] so that:

$newlist[0]=$list[0]->member2;
$newlist[1]=$list[1]->member2;
$newlist[2]=$list[2]->member2;
....

I need to do this using A SINGLE LINE OF CODE.
Is it possible? How to do this?

I tried with:

array_walk($list,create_function('$a,$b,$result',' $result[] =
$a->member2;'), &$result);

but I get the following error:

Warning: Call-time pass-by-reference has been deprecated - argument
passed by value; If you would like to pass it by reference, modify the
declaration of array_walk(). If you would like to enable call-time
pass-by-reference, you can set allow_call_time_pass_reference to true in
your INI file. However, future versions may not support this any longer.

View Replies !   View Related
How To Create An Array?
how to create an array that contains cat01, cat02,cat03..., cat17 and the cat01 has a value equal to 1, cat02 has a value = 2, cat17 has a value =17 ??? (means every cat01-cat17 has a value assigned to).

View Replies !   View Related
Create A 2D Array?
How do I create a 2D array?

View Replies !   View Related
Create Array &
I am currently trying to create an array within a query that populates the array with a double number such as 10.21 and the primary key from the query such as 1451. After the query is finished, I want to sort the array by the double number (10.21) and then do a query based on the primary key (1451). I tried using the key as 10.21 and the val as 1451 and it works, but I may have multiple 10.21 numbers, and it omits it since it is already in use.

Also, sorting by the key doesn't consider the key numbers so 2.84 comes after 18.44. What is a good work around to capture the double and primary key integer and sort the array by the double? I don't mind changing the array around so I don't lose data on the sort, but I still need to sort the array by the double.

View Replies !   View Related
Create An Array
I did try to search, but when I click on "GO", nothing happens. For some reason it is not working. In fact, nothing is working for me today. Here's my problem:

$myArray = array(1,2);
-or-
$myArray = array(&#391;',&#392;');
-or-
$myArray = array("1","2");

all return "Fatal error: Call to undefined function: array()"

View Replies !   View Related
Create One Array From Two
I have two arrays

customers[]
cust_id => 0001
cust_name => Joe

locations[]
cust_id => 001
cust_location => Montana

How can I efficiently merge these two together to create just one array:

customers2[]
cust_id => 001
cust_name => Joe
cust_location => Montana

The only way I can think of doing this is to loop through one and do an array_search on the other. If found just create a new array with all three fields.

This seems a bit inefficient as if I have 1000 customer id's then a maximum of a million iterations could be performed. Is there already a function to create one array from two?

View Replies !   View Related
Create An Array Of All The Days
lets say i have 09/01/2001 and 09/20/2001. I want to create an array of all the days including the two that are the start and end of the range. how would i go about doing this?

View Replies !   View Related
Create A Multidimensional Array From XML Doc
Currently I have the following XML document:

<Programs>
<Program>
<ProductTypeName>30 Yr Fixed</ProductTypeName>
<Rate>6.250</Rate>
<APR>6.274</APR>
<InvestorName>Helos</InvestorName>
<Payment>2832.298</Payment>
</Program>
<Program>
<ProductTypeName>30 Yr Fixed</ProductTypeName>
<Rate>9.250</Rate>
<APR>9.293</APR>
<InvestorName>Avalon</InvestorName>
<Payment>3784.306</Payment>
</Program>
<Program>
<ProductTypeName>5/1 Arm</ProductTypeName>
<Rate>6.375</Rate>
<APR>6.399</APR>
<InvestorName>Carl1</InvestorName>
<Payment>2869.802</Payment>
</Program>
</Programs>

I load it up in a domdocument and iterate through it with the following:

$returns = array();
for($i = 0; $i < $xmlproducttype->length; $i++)
{
$returns[$i]['ProductTypeName'] =
$xmlproducttype->item($i)->nodeValue;
$returns[$i]['InvestorName'] =
$xmlinvestorname->item($i)->nodeValue;
$returns[$i]['Rate'] = $xmlrate->item($i)->nodeValue;
$returns[$i]['APR'] = $xmlapr->item($i)->nodeValue;
$returns[$i]['Payment'] = $xmlpayment->item($i)->nodeValue;
}

Giving me the following style array:

View Replies !   View Related
Using A Loop To Create An Array
I am trying to populate an array with information found in a mysql database. By selecting a state they would then see every resort that contains the selected state in it's row... Kind of like a tree navigation system. Code:

View Replies !   View Related
Create Array With Loop
I have got a problem creating an array. I have 3 arrays with words in them. I read those words and compare them with eachother to set the final number of words and give them a score. I do this with a couple of loops and set new a variable which should become a new array.

This new array (word_combi) contains the word, the number of times is was in the total list and the score. I have got the code I use below (which doesn't work)...can anyone tell me my error and point out the way to fix this? PHP Code:

View Replies !   View Related
How To Create New Array With Each Loop
I've got a while loop that's doing some stuff, and what I want is for it to create a new array each time. I only seem to be able to add to the existing array each time though - I'm sure there must be a simple way of doing this but it evades me at the moment!

while(condition){
//do some stuff
//create an array $dirarray[]
//amend values in array
//save as new array each time? e.g.$dirarray1[], $dirarray2[] etc. until loop finished
}

View Replies !   View Related
How To Create Multidimensional Array?
I have a table that looks like this:

ID --> Product --> Color --> Size
1 --> Shirt --> Brown --> S
2 --> Shirt --> Brown --> L
3 --> Shirt --> Brown --> XXL
4 --> Shirt --> Black --> M
5 --> Shirt --> Black --> XS
6 --> Shirt --> Red --> XL

I'm trying to create an array that looks like this:

Array ( "Brown" => array("S", "L", "XXL"), "Black" => array("M", "XS"), "Red" => array("XL"))

The following gives me two separate arrays, one for colors, and one for sizes: Code:

View Replies !   View Related
Create Indexed Array
I use a class that allows me perform certain queries. For example, I can get results from a table like this: PHP Code:

$myarray = $db->get_results("SELECT page FROM t1
WHERE item = '$book'");

foreach ( $myarray as $val )

{
            // Access data using object syntax
            echo $val->name;
}

View Replies !   View Related
Create Array Of Arrays
How is this done in php? I've tried several variations of the following:

contact_array[] =
($_POST['contact_relation'],
$_POST['contact_first_name'],
$_POST['contact_last_name'],
$_POST['contact_phone'],
$_POST['contact_email']);

The ultimate goal is to insert the array into a table in a Mysql db.

View Replies !   View Related
How Do You Create An Array From A While Loop?
How do you create an array from a while loop? Basically i want to list out all the files within a directory (below)

$dh = opendir($img_dir_1);
while($file = readdir($dh)){
if ($file != '.' && $file != '..' && $file != 'Thumbs.db'){
print ($file)."<br>";
}
}

Then i want to build each $file into an array and randomly select one using the array_rand() function.

View Replies !   View Related
How To Create Html List From Such Array ?
I've got an example array like this:

$myArr = array(
array("jj", "0", "jjj"),
array("ee", "0", "eee"),
array("bb", "ee", "bbb"),
array("ll", "ee", "lll"),
array("ff", "0", "fff"),
)

Where each row is an array with columns: id of list element, id of parent
list element ("0" means main node) and content of the element. So, from my
array I'd like to create a list like this:

<ul>
<li>jjj</li>
<li>eee
<ul>
<li>bbb</li>
<li>eee</li>
</ul>
</li>
<li>fff</li>
<ul>

View Replies !   View Related
Create Array From 2 Database Fields
I want to create an array of product prices, with the product id as the index and the product price as the value, so i can place the prices for particular products wherever i want on my page.

Both product id and price are taken from the Products table
SELECT prod_id, prod_price FROM Products

Due to the client wanting an unusual layout, I cant just loop a table with the data, I need to be able to print $Price[2]; (for product id 2) wherever I like, for example.

View Replies !   View Related
Create A Delimited Text Array
How can I create a delimited text file to work with this script. I would like to put this first part in a text file and load it into an array so the php script can parse it. Code:

View Replies !   View Related
Create One Array That Will Hold Numbers From 3 To 50
How to create one array that will hold numbers from 3 to 50, their
square roots, and number * 10?

example: 3, 1.43, 30
4, 2, 40

View Replies !   View Related
Loop Through The Array And Create A Category
I have an array of id=>category:

[018821] =Automotive Parts
[222033] =Automotive PartsDomestic
[205884] =Automotive PartsForeign
[987219] =Building Supplies
[624668] =Building SuppliesLumber
[063964] =Building SuppliesLumberHardwood
[592999] =Building SuppliesLumberHardwoodSteel
[987808] =Building SuppliesLumberStructural
[169626] =Building SuppliesLumberTreated
[966554] =Building SuppliesPlumbing
[329645] =Construction Adhesives
[621126] =Roofing Supplies
[400762] =Roofing SuppliesAsphalt Roofing
[475138] =Roofing SuppliesMetal Roofing

What I'm trying to do is loop through the array and create a category
tree:

Automotive Parts
Domestic
Foreign
Building Supplies
Lumber
Hardwood
Steel
Structural
Treated
Plumbing
Construction Adhesives
Roofing Supplies
Asphalt Roofing
Metal Roofing

View Replies !   View Related
Create Multidimensional Array Dynamically
I'm already trying for some days to create an array dynamically. I have the following situation:

I have an array of strings.

$data["base:foo:bar"] = "test1";
$data["base:foo2:bar"] = "test2";
$data["base:foo2:bar2"] = "test3";
$data["base:foo:bar2"] = "test4";

This array should be converted in a multidimensional array. The keys for this array are the above keys separated by colons. The dimension of the array varies form situation to situation. Code:

View Replies !   View Related
Create Array(?) Of Subdirectory Names
I want to output an RSS feed based on text in identically named files located in different subdirectories (at the same level). So the structure looks something like: /dir/subdir1/text.txt, /dir/subdir2/text.txt, /dir/subdir3/text.txt, etc.

Therefore, how can I create an array of these subdirectory names, and then loop through those directories to echo the text.txt content?

View Replies !   View Related
Create Multi Dimensional Array
$miles_zip = array();

foreach ($subzip as $key => $value) { //3

$miles = $z->get_distance( $zipCode, $key);

$miles_zip[$i] = $miles ;
$i++;
} //3

$count = count($miles_zip) ;

for ($i = 0; $i < $count; $i++)
echo " $miles_zip[$i]<br> ";

I am trying to put $key and $miles in a multi dimensional array. I have tried different ways, it is not working. All I see online is syntax of creating static multidimensional arrays. Can somebody guide me how can I create a dynamic one.

View Replies !   View Related
Create Objects In An Array Within For/while Loop?
Why can't I create Objects in an Array within for/while loop?

If I have:

$galleries = array();

while( $db->next_record() )
{
$foo = $db->f('id');
$galleries[] = new Gallery($foo);
}

Database query returns two id's and galleries array should then
contain two Gallery Objects but it contains only the first one.

If I do it like this, it works fine:

$galleries[] = new Gallery(1);
$galleries[] = new Gallery(2);

I have PHP 5.1.6

View Replies !   View Related
Create An Array With Multiple Elements
I want to create an array with index 'dog1', 'dog2'. Each dog index should have 3 elements for 3 different colors. How do I do it? Do I need to use multiple dimensional array? I try not to use multiple dimensional array. Maybe something like this?

$dog = array('dog1' => 'red', 'blue', 'black',
'dog2' => 'white', 'blue', 'red);

View Replies !   View Related
Create A Mysql Query Out Of An Array.
I am trying to create a Mysql query out of an array. Here is my code.

$lookup = mens jackets;
$lookup = explode(' ',$lookup);
$count=count($lookup);

for($i=1; $count >= $i; $i++){
$query =("select * from stuff WHERE description LIKE ('$lookup[0]')
$query .= AND ('$lookup[$i]')
$query .= ");}

here are my results I am getting; Code:

View Replies !   View Related
How To Get PHP To Create An Array Of A Given Directory's Structure.
I'm trying to find out how to get PHP to create an array of a given directory's structure. E.g Structure Array =

1 - Blue Images
2 - Red Images
3 - Pink Images
4 - Brown Images

The above strucutre will be changing daily, so I need this to be dynamic.

View Replies !   View Related
Would Using An Array To Create Objects Be Wise?
I am in the process of making a project, trying out some code and mainly planning it at this stage. I have a question that I believe will greatly influence the way the code will be designed...

I would like to create objects in an array instead of vars like this: Code:

View Replies !   View Related
Use Function To Create My Own Order For The Array.
I am having a small problem with array.

I have an array which may look like this: array(6,"*","-",7);

when I sort these it looks like * - 6 7

What I am trying to do is sort it so that it sorts the - as the first item

So I am trying to end up with an array that looks like this: - * 6 7 (with the * and - swapped around)

none of the sort functions seem to be able to do this.

Perhaps the usort would but I am not sure I quite understand how I would use that function to create my own order for the array.

View Replies !   View Related
Create Array From Comma String
I am currently learning from the book, Eric Rosebrock's "Creating interactive websites with PHP and web services" it is a great book, but I have a question. I have a string loaded from mysql that looks like this: PHP Code:

$allowedfiletypes = '".jpg", ".tif", ".gif", ".png"'

I want to turn this into an array but its not working, I'm trying something like: PHP Code:

$allowedfiletypes = array($allowedfiletypes);

so that if I print_r it it will output something like:
[0] => .jpg
[1] => .gif
[2] => .png
etc.

View Replies !   View Related
Problems With Dynamic Checkbox - Need To Create Array
The problem I have concerns a dynamically created table/form which pulls in results from a user search of a mysql database. This works fine and pulls in results (title/author/isbn/price) and dynamically creates the table dependent upon how many results are found. For each result there is a dynamically created checkbox, which is bound to a unique field from the database(in this case isbn).

My problem then is: the dynamically created checkbox submits an isbn value to the next page - an order form. However I need that a user can select a number of checkboxes from the table. At the moment, each selection overwrites the other. It may be vary obvious - but I need to work out some way of storing the checkbox info in an array that gets submitted to my order form page.

at the moment the code for my checkbox within the html form is:


<input name="isbn_input" type="checkbox" id="isbn_input" value="<?php echo $row_Rs_panozzo_search['isbn']; ?>" />
</font></td>

This works passing one value through to my order form, but I need to set it up so it passes multiple values.

View Replies !   View Related
Create A Optgroup Dynamically Based On The Value Of An Array
how to create a optgroup dynamically based on the value of an
array...

for eg....

View Replies !   View Related
Looping Database Values To Create An Array
I have a fairly simple php code problem I think, I want to loop values from a mysql database within an array to fill the array. I'v never done this before so your help would be valued if someone had the time.

*denotes where I want to use database values*

View Replies !   View Related
Create An Array From A List Of IDs Within A Database Table
I need to create an array from a list of IDs within a database table. The table consists of 3 fileds, a unique ID, a user ID and the last is an int value (item number)

eg
1 3 7
2 4 5
3 3 2
etc...

How would I go about using this query

$query1=mysql_query("SELECT itemnumber FROM table WHERE userid = '{$user}'");

Would i be right in thinking I can use:
$array = mysql_fetch_array($query1);

to store all the item numbers associated with the user specified in the first query?

View Replies !   View Related
What Function Is Necessary In Order To Create The Array Of Images?
i am trying to start a photography business, and what i want to accomplish is to be able to dynamically create a gallery. the script will simply look in the folder i specify, display 20 photos per page, and allow the user to click each photo to enlarge it.
 
what i want to know is what function is necessary in order to create the array of images?

any other information/snippets which pertain to my goal would be appreciated. i've been searching the forum but have yet to find a similar post in relation to what i am trying to obtain.

View Replies !   View Related
Array_multisort - How To Create A New Array For Data And Sort It.
I have some code that retrieves a list of dealers. I need to sort thsi list on a field that doesn't exist in the tables.

Distance from customer will be the field (I have a function for this). I can calculate this but once I get the distance how do I resort the list in ascending order by distance.

The code below displays all the dealers but not the closest one first. It is pretty random. Like I said I know how to calculate the distance but don't know how to create a new array for this data and sort it.

Here is some pseudo code that I am using ...

View Replies !   View Related
Dynamically Create Variables By Traversing Array
Is there a way to dynamically create variables by traversing an array, then naming the variable with the position in the array? for example....

for ($i=0; $i<count($_SESSION['order']); $i++)
{
create variable named $posei;
$posei=$i;
}

View Replies !   View Related
Fetch Array - Create A $_SESSION Variable
I am writing a contact management php page. In the page I use mysql_fetch_array() to show the search results. If the user searchs by first name, there are times when multiple entries come up. Once the data is displayed on the screen the user has the option to edit, or delete this entry in the database. So on this one screen it shows all the search results.

If the user clicks on edit or delete, I then create a $_SESSION variable to bring this information to the edit or delete page. However this variable only gets created for the first entry when I do the mysql_fetch_array(). If I choose any entry after the first, it brings over the first entries information. How would I create a variable to bring this over to another page to edit or delete each specific contact. Is there a better way to do this?

View Replies !   View Related
How To Correctly Create An Array Of The Same Type Objects ?
how to correctly create an array of the same type objects ? First I thought I should declare every element of an array as my object and it works (I'll skip class definition, it is irrelevant): Code:

View Replies !   View Related
How To Create A Multi D. Array From Single Query
I am trying to build a multidimensional array with a single query. Code:

View Replies !   View Related
Try And Create A Session Array - Multidimensional Arrays
I have created a multi-dim array as below

$next[] = array("name" => $data[name], "url" => $data[url]);


this works fine and I get the results I want, however when I try and create a session array as below

$_SESSION[next]=$next;

all I am getting is the name the url is NULL.

View Replies !   View Related
Create An Array With Multiple Words As Index
I want to create an array with multiple words as index. e.g.

myarray = array();
myarray["my dog"] = 1;
myarray["my cat"] = 1;

View Replies !   View Related
Create An Array From Variable Seperating The Values By Comma?
I have a variable with the following values...

$variable = "3,6,9,12";

How would I create an array from this variable seperating the values by comma?

$array = array($variable);

Above doesnt work, it doesnt split the array in seperate values, it thinks "3,6,9,12" is one value?

View Replies !   View Related
Create An Array Indexed By One Of The Values Returned From Query.
I need to create an array indexed by one of the values returned from query.

$query = "SELECT ID, Name, Number FROM Table";

I want to store the result in an array indexed by "ID" so I can refer to it as $arr['ID'].

I want to be able to get a selectedIndex.value of a dropdown and use it as index to this array to get other values, such as Name and Number.

View Replies !   View Related
Create A Comma Delimited String That I Can Convert To An Array Using Explode();.
I am attempting to create a comma delimited string that I can convert to an array using explode();. I have the following code: Code:

$cPath_new_a = tep_get_path($categories['categories_id']);
$cPath_new_b = str_replace("cPath=", "", "$cPath_new_a");
$cPath_new_c = str_replace("_", "", "$cPath_new_b");
$cPath_new_d = substr("$cPath_new_c", -2, 2);

$cPath_new_e = $cPath_new_d . ",";

echo $cPath_new_e;


This outputs 23,53,

I need it to output 23,53 Using the substr($cPath_new_e, 0, -1); and/or rtrim() method to remove the last character for some reason removes all of the commas. Am I approaching this the right way?

View Replies !   View Related

Copyright © 2005-08 www.BigResource.com, All rights reserved