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.





Sorting A Multidimensional Array


I Have an array set as so:

$temparr[$i]['score'] = 3.4
$temparr[$i]['id'] = 1
$temparr[$i]['title'] = 'title'

$i loops the array populating it, but when I output the array, i would like to sort it by the 'score' value asc or desc, depending on what i want to show... what is the easiest way of achieving this?




View Complete Forum Thread with Replies
Sponsored Links:

Related Messages:
Multidimensional Array Sorting
I'm having some trouble sorting a multidimensional array I have created. The use of this sorting is to set up "standings", sorted by WINS descending, LOSSES ascending, and TIES descending. The array looks as such: Code:

View Replies !   View Related
Array Sorting (multidimensional)
I have an array:

array(2) { [0]=> array(1) { ["pageID"]=> string(1) "8" } [1]=> array(1) { ["thematch"]=> float(1.34) } [2]=> array(1) { ["table"]=> string(2) "ct" } [3]=> array(1) { ["pageID"]=> string(1) "6" } [4]=> array(1) { ["thematch"]=> float(1.33) } [5]=> array(1) { ["table"]=> string(2) "ct" } }

The problem - I want to sort this array by the second level key value of "thematch".

I've tried using the various sort, ksort, asort etc but to no avail.

Can someone suggest a way to sort this array by the value (in descending order) of that key?

View Replies !   View Related
Sorting Multidimensional Array
I have a multidimensional array that i need to sort by value. An example of the array is as follows

$myarray[0]['price']=1400;
$myarray[0]['txt']="my arrays txt";
$myarray[0]['acer']="5";

$myarray[1]['price']=1500;
$myarray[1]['txt']="my arrays txt 2";
$myarray[1]['acer']="1";

View Replies !   View Related
Sorting A Multidimensional Array On Two Columns
I'm working on some low-tech sort of content managing system. It uses textfiles as a kind of database so the users don't have to install SQL on their server. Now I want to perform some sorting on my files. These are the contents of one of those files.

PageName;Template;Menu;Sub;
Introductie;1;1;1;
Opnemen;1;2;0;
Voorbereidingen;1;2;2;
Kwaliteit;1;1;0;
Blabla;1;2;1;

I first read this file into $someArray with file() and then I parse each row with explode() into columns. So $someArray[2][2] contains the value 2 and $someArray[0][2] contains "Sub".

I want to sort this array on both Menu and Sub and write it back to the file. It should look like this.

PageName;Template;Menu;Sub;
Kwaliteit;1;1;0;
Introductie;1;1;1;
Opnemen;1;2;0;
Blabla;1;2;1;
Voorbereidingen;1;2;2;

I want to make a list of menus and their listed submenus in the proper order, as you can see .

What is the clever way to do this? At this moment I use a loop that sorts the submenu in a loop that finds the right menu in a loop that sorts the menus. No, it's not you, I don't understand it myself anymore. That's because I don't understand most of the array principles and functions.

View Replies !   View Related
Sorting Multidimensional Array - Multiple Varients
I am sorting a multidimensional array ($listing), using the following code:

function compare ($x, $y) {
if ( $x[1] == $y[1] )
return 0;
else if ( $x[1] < $y[1] )
return -1;
else
return 1;
}
usort ($listing, 'compare');

However, I would like to set up a sorting function in which I can dynamically select which value to sort by. So I tried multiple varients of the below code, but I can't seem to get the "$i" varible to work. Is there a way around this, or a better script out there?

View Replies !   View Related
Sorting Multidimensional Array - Used Sort Function
I have the following multidimensional array:

Array ( [1] => Array ( [0] => 0 [1] => 2 ) [2] => Array ( [0] => 1 ) )

I would like to have the following array:

[1] 0
[2] 1
[1] 2

Is this possible to do?

View Replies !   View Related
Sorting Multidimensional Arrays
sorting a regular non-associative array I have an array $products[0][1] where $products[0] holds a name of a product and $product[1] holds a rating for that product. I need to sort the products by rating and still have the product and the rating together. I figured out one way to do it with an array_multisort, but it only sort the ratings and left the products unchanged.

View Replies !   View Related
Sorting Complex Multidimensional Arrays
I read several threads on sorting and I understand usort() is the way to go, however, I do not know how I can sort the following array: Code:

View Replies !   View Related
Sorting Multidimensional Arrays On A Named Dimension?
I usually store info in arrays using field names

$array[1]["country"]='Germany',
$array[1]["code"]="GE";

$array[2]["country"]='United Sates"
$array[2]["code"]="US";

$array[3]["country"]='France"
$array[3]["code"]='FR"

I want to get:
$array[1]["country"]='France"
$array[1]["code"]='FR"

$array[2]["country"]='Germany'
$array[2]["code"]="GE";

$array[3]["country"]='US"
$array[3]["code"]="US";

Is there a function to sort on a field (country in this case)

View Replies !   View Related
Multidimensional Array Syntaxt For Preg_split Array Using Submitted Textarea
I have two textarea's called textarea1 and textarea2.  What i did was use preg_split to split the textarea into seperate rows that i could use for analysis like so

$array = preg_split("/[
]?[
]/", $_POST['textarea2'], -1,PREG_SPLIT_NO_EMPTY);
$array2 = preg_split("/[
]?[
]/", $_POST['textarea1'], -1, PREG_SPLIT_NO_EMPTY);

then i used a function created for me by a nice guy on here called get_ending($filepath) which basically stripped off of each peice of text the "http://www" from every URL i put into the textareas

finishing off i wanted to create an array that would input an expression such as:

echo "<a href='$array[1]' target='_blank'><img src='$array2[1]' border='0'>";

into a text area on the next page.  ALL of this works, except that i dont know how to properly loop throught he array so it'll properly insert the text into the textarea on the next page.

For now, all it does is place the array information in the page, rather statically, i would like to run some kind of if then statement that says

"while $array has some kind of text in it, keep running this operation of echoing the following expression adding 1 to the end of the array number"  I hope that makes sense

Any ideas? Code:

View Replies !   View Related
Accessing Array Values Inside A Multidimensional Array
I need to access a value which is inside in a multidimensional array...

Suppose there is a form and where I takes all the form values inside an array named access..and I post the values into a different array.

$registrationArray = $_POST['access'];

Now I need to loop through this registration array and get values printed to the new variables...

Suppose this is the array $access = array (fname,lname,date,year,month)

How do I print the date,year,month values into different variable by looping through registration array..

View Replies !   View Related
Passing Array Of Multidimensional Array To Function
How do I pass a part of a multidimensional array to a function. I have the following (in pseudo):

$arrays[m][n]; // filled with values
$chosen = 3;

function doSomething($array) {
 // do something with 1D array
}

This fails:

doSomething($arrays[$chosen]);

Can someone explain to me why? And how to do this right?

View Replies !   View Related
Multidimensional Array: See If 1st Key Is Available
I've got an multidimensional array
$ret = $country_code[$countryCode][$langCode];

Now I want to see if $countryCode is even in that array, because if it's
not, it doesn't make many sense to look further for $langCode.

Eg.

$country_code = array('BE' =>
array ('en' => 'Belgium',
'nl' => 'België'),
'NL' =>
array ('en' => 'Netherlands',
'nl' => 'Nederland'),
);

Searching for 'BE' would make sense, but 'LP' wouldn't.

I already tried:
$arr = array($country_code['LP']);
if (sizeof($arr) == 0)
print "LP not found!"

But that doesn't seem to work :-s.

View Replies !   View Related
Multidimensional Associated Array
I try to construct an array such that each element of it is another
array returned by the fetch_array_function:
for ( $i = 1; $i<=$n; $i++ )
{
$ar[$i] = mysql_fetch_array( $result );
print "$ar[$i][fieldname]
";
It prints "Array[fieldname]".
If I replace $ar[$i] by $ar everything works fine! Could you pleas...

View Replies !   View Related
2 Multidimensional Array
I have a multidimensional matrix:

C1 C2 C3 C4
R1[] [] [] []
R2[] [] [] []
R3[] [] [] []
R4[] [] [] []
R5[] [] [] []
R6[] [] [] []
R7[] [] [] []
R8[] [] [] []

1. Is it possible to search in a specific column? eg: only search for a value in in C2 and get the rownumber as result?

2. Copy one or more rows and put them in between other rows? eg: move row 5 and 6 between row 1 and row 2.

C1 C2 C3 C4
R1[] [] [] []
R5[] [] [] []
R6[] [] [] []
R2[] [] [] []
R3[] [] [] []
R4[] [] [] []
R7[] [] [] []
R8[] [] [] []

View Replies !   View Related
Multidimensional Array
I am trying to build a random card generator and once a card is chosen it gets taken out of the array. this is what i have so far which is far away from where I need to be.

$suites = array("Spade","Clubs","Diamonds","Hearts");
$numbers= array(2,3,4,5,6,7,8,9,10,"Jack","Queen","King","Ace");

View Replies !   View Related
How To Reference An Array In Multidimensional Array?
How do I reference an array within an array?

$mapped_array = array_map(null, $data_array, $counter_array);

// okay, so now I have an array of 2 arrays - but how do I reference each
array?
// the next two lines fail to give an accurate count
echo "Starting with ".count($mapped_array[0])." elements in
data_array<br>";
echo "Starting with ".count($mapped_array[1])." elements in
counter_array<br><br>";

// now I want to start at the bottom and look for an IP in each line of
data_array
// which I assume is mapped_array[0]
for ( $i=count($mapped_array[0]); $i > 0; $i-- )
{
$data_line = $mapped_array[0][$i];
$data = explode("|", $data_line);
if( in_array($ip, $data) )
{
// if there's a match, element[$i] of both arrays needs to be spliced
out
array_splice($mapped_array,$i,1);
}
}
// again, these next two lines fail to return an accurate count
echo "Ending with ".count($mapped_array[0])." elements in data_array<br>";
echo "Ending with ".count($mapped_array[1])." elements in
counter_array<br><br>";

Is there something about array_map that prevents me from referencing the
arrays within the array?

View Replies !   View Related
Problems Using Multidimensional Array
I am trying to understand multidimensional arrays within PHP, and am trying to do the following:

$x[1][1]="test";
$x[1][2]="test2";
$x[2][1]="test3";
$x[2][2]="test4";
print ("$x[1][1] $x[1][2] $x[2][1] $x[2][2]");

but instead of getting the result:
test test2 test3 test4

I am getting:
Array[1] Array[2] Array[1] Array[2]

Can someone please explain why this is happening.

View Replies !   View Related
Break Down Multidimensional Array
I have a multidimensional array and was wondering how it can be broken down...

Array
(
[0] => Array
(
[0] => Array
(
[0] => 1
[intsch_id] => 1
)

[1] => Array
(
[0] => 2
[intsch_id] => 2
)

)

)

And I want to break it down to

Array ( [0] => 1 [intsch_id] => 1, [1] => 2 [intsch_id] => 2) And this is in a dynamic query, so the results won't always be this simple. It will have the same structure as the above multidimensional array.

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
Passing Multidimensional Array Thru The URL
I have an issue with an array that I would to pass to a second php
script; please note that I cannot use session.

I have been looking at the functions : rawurlencode / rawurldecode
urlencode / urldecode but it does not seems to work for my variable

here is an example of variable:

<?
$x=0;
$data[$x][title]="My title";
$data[$x][label]=array("label1","label2","label3");
$data[$x][data]=array(100,150,145);
?>

How can I pass this variable thru an URL?

View Replies !   View Related
How To Return A 'sub-array' Of A Multidimensional One
I have a multi-dimensional associative array, and I'm interested in searching the array for a given key, and returning the 'sub-array' or value associated with this key. for example:

Code: $array = array( 'A'=>1, 'B'=>2,
'C'=>ARRAY( 'A2' => 'FRUIT', 'B2' => 'VEGGIE',
'C2' => ARRAY( 'MEAT1' => 'BEEF', 'MEAT2' => 'CHICKEN' ) ) );

I want to retrieve the array under the key 'C2'. I have tried to 'search' the array so that its internal pointer is pointing at this element, then using 'current', but that doens't work: Code:

array_key_exists( 'C2', $array );
var_dump( current( $array ) );

I've also tried a small variation of the above in order to get the reference to C2 rather than a deep copy: Code:

array_key_exists( 'C2', $array );
var_dump( $array[key($array)] );

I would actually prefer to get a reference into the array rather than a copy.. I guess I'm really stuck on the 'search' part of the mutlidimensional array.. Surely there's a better way (built-in function) than iterating every element and comparing the key?

View Replies !   View Related
Multidimensional Array Merge
I need one solution for multidimentional array merging option using php. Please send me any samples multidimensional array merging.

View Replies !   View Related
Single Array To Multidimensional
I have a string, comma separated, with links and their respective URLs
in it. Example:
Google,http://www.google.com,Yahoo!,http://www.yahoo.com,WikiPedia,http://www.wikipedia.org

etc, etc.

i make an array of this with explode( ',', $string );

now what i wonder is how can i turn this array into something like
this:

$array[0]['name'] = Google
$array[0]['url'] = http://www.google.com
$array[1]['name'] = Yahoo!
$array[1]['url'] = http://www.yahoo.com
$array[2]['name'] = WikiPedia
$array[2]['url'] = http://www.wikipedia.org

I hope/think this is all clear ...

View Replies !   View Related
Define The Multidimensional Array
I won't post my exact code since the project I'm working on is HUGE and I'd have to explain it all anyways, but I'll provide examples. Basically, I'm using OOP PHP to build this project... and at one point I have the constructor of 'Class1', calling another method of the same class. In that method, I want to add to a multidimensional array defined in the class itself... in the first position I want to store a string, in the next position, I want to store an instance of another class.

Now, the problem I'm having is that when I try and define the multidimensional array, it takes FOREVER!!!! Literally 25 seconds! All I'm doing is this: PHP Code:

View Replies !   View Related
Multidimensional Array Loop
I am trying to loop through a multidimensional array shopping cart stored in a session. I can loop through it ok but the problem is that when the page displays I have two each of the items in the cart. I am looping through with a double foreach.

If I do print "$key: $value"; inside of the second foreach I get the correct display of the items in my cart but then the actual display of the items gives me two of each. Code:

View Replies !   View Related
Multidimensional Array Declaration In Php
how to achieve that? it seems php doesn't support it well for a C
programmer?

i hope to use something like:

a[$i][0];

a[$i][1];

a[$i][2];

View Replies !   View Related
Checkboxes In A Multidimensional Array
I found this nice code online that does exactly what I want it do to: Emails a form that includes the posted values. I can get the text boxes, text areas, and radio buttons to send; however I cannot for the life of me figure out how to get checkboxes to send. It will only send the last-checked value. I have searched the internet and seen that this is a common problem, but I have not found anything similar to the code that I am using. Code:

View Replies !   View Related
Change Into Multidimensional Array
I have an array that looks like this:

Array
(
   [0] => Array(
      [fieldID] => 001
      [description] => Hi all!)
   [1] => Array (
      [fieldID] => 002
      [description] => It’s me again! )
)
And I want to change it into array that would look like this:
Array
(
   001 => Hi all!
   002 => It’s me again!
)

Is it possible to do it at all?

View Replies !   View Related
Deleting Multidimensional Array
if i have a multi dimentional array, eg:

$arr[x][y] = '';

and i want to delete the enrite thing, does unset($arr); rowk, or so i have to delet the second arrays, or how do i do it???

View Replies !   View Related
Foreach() Multidimensional Array
I did a search for other foreach() problems and cant seem to find a solution that fits my syntax, probably because I'm a newbie. Here is my code:

View Replies !   View Related
Jump Out Of A Multidimensional Array?
trying to get out of an array dynamically.

$transport = array('foot', 'bike', 'car', array('test1', 'test2'));
i'm in test2( $transport[3][1] ), how do I go into $transport[3]? Is there a function capable of doing this?

View Replies !   View Related
Adding To Multidimensional Array
I'm realtively new to PHP and I'm trying to get my head around a particular issue. I've got an array that looks like this:

$field_array = array (
array (field=>"dist_Company", type=>"text"),
array (field=>"dist_Active", type=>"select", options=>array(array(oname=>"yes", oval=>"1"), array(oname=>"no", oval=>"0"))),
array (field=>"dist_CompanyID", type=>"select"),
array (field=>"dist_Shipping", type=>"text")
);

What I'm trying to figure out is how to add to this array after it's been defined. In this case I'm trying to add the "options" subarray to dist_CompanyID element so that it has options similar to those predefined in the dist_Active element.

I can do it if I specify the index like this:

$field_array[2]['options'][] = array(oname=>"one", oval=>"1");
$field_array[2]['options'][] = array(oname=>"two", oval=>"2");
$field_array[2]['options'][] = array(oname=>"three", oval=>"3");

Is there some elegant way to find the index number for the element containing field=>"dist_CompanyID"?

View Replies !   View Related
Yet Another Foo Bar Multidimensional Array Problem
I have a script that out puts an array like this: Code:

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
Add Paging To A Multidimensional Array ?
how to add paging to a multidimensional array ?

View Replies !   View Related
Unique-ing A Multidimensional Array
I am storing a 3-dimensional array in $_SESSION. The important data has this form:

$_SESSION["items"][item_type][item_subtype].

I need to make sure there are no duplicates, where duplicate means the item type and subtype match. I have looked at the comments on php.net for array_unique, and there are multiple posts that claim to provide code for unique-ing a multidimensional array, but I could not get any of them to work. I am wondering if it has something to do with the fact that I'm using $_SESSION.(?). What I want to do (pseudocode) is:

array_unique($_SESSION["items"]).

View Replies !   View Related
Building Multidimensional Array
In my database I have a couple of fields and I'm trying to create multidimensional arrays out of them. For example, in my db, I have:

Colors | Price
red,blue,yellow | 50,45,32
yellow,green,purple | 12,47,82
gold | 39

I'd like to build arrays that looks like this:

array('red' =>&#3950;', 'blue' => &#3945;', 'yellow' => &#3932;')
array('yellow' =>&#3912;', 'green' =>&#3947;', =>', 'purple'=>&#3982;')
array('gold' => &#3939;')

Is there a way to do this? I've looked at the array functions in the php manual, but I still don't understand how I can build these from queries to my db.

View Replies !   View Related
Multidimensional Array Confusion
If I print_r($_POST) the values submitted by my form, I'll get this: PHP Code:

Array (
    [Name0] => Doe
    [Age0] => Array ( [0] => 23 [1] => 28 [2] => 32 [3] => 11 [4] => 9)
    [Name1] => Smith
    [Age1] => Array ( [0] => 7 [1] => 8 [2] => 9 )
    [Name2] => Jones
    [Age2] => Array ( [0] => 54 [1] => 42 )
    [submit] => Submit
)

I'm trying to figure out how to match up the Name/Age arrays so that when I submit it, I'll be able to store the information in my database like this:

id Name Age
1 Doe 23,28,32,11,9
2 Smith 7,8,9
3 Jones 54, 42

Is there a way to do this?

View Replies !   View Related
Usort Multidimensional Array
I would like to sort the following array by the "make" AND the "model"... it currently sorts by "make" just fine. PHP Code:

//Function
function sortColumn($a, $b)
{
   return strcmp($a["make"], $b["make"]);
}

//Array
$cars = array(
  array('make' => 'Ford', 'model' => 'F250'),
  array('make' => 'Honda', 'model' => 'Civic'),
  array('make' => 'Honda', 'model' => 'Accord'),
  array('make' => 'Ford', 'model' => 'F150'),
  );

...................

View Replies !   View Related
Multidimensional Array Search
I have a multidimensional array on football statistics. I need to search the array for a specific team, and return that teams key (which row the teams statistics are in). Code:

View Replies !   View Related
Multidimensional Array Problem
I have the following multimensional Array:

Array ( [Cadence Healthcare,Montreal,Canada] => Array ( [0] => 0 [1] => 2 ) [Merck,London,Canada] => Array ( [0] => 1 ) )

I want to be able to assign in a array:

Last_Name[0] = Cadence Healthcare,Montreal,Canada
Last_Name[1] = Merck,London,Canada
Last_Name[2] = Cadence Healthcare,Montreal,Canada

View Replies !   View Related
Grouping Multidimensional Array
I have a 3D array that I'm trying to traverse and wondering the best way to group results? The query returns

category | item | note
3 | 1200 | socks
3 | 1440 | stockings
8 | 400 | wool hat

How can I group these? PHP Code:

View Replies !   View Related
Searching Multidimensional Array
Here is the array.

$playerarray = Array ( [0] => Array ( [Team] => jimmydee2 [Player1] => jimmydee2 ) [1] => Array ( [Team] => jimmydee2 [Player1] => jimmydee2 ) );

here is my code to search it for a variable

foreach($playerarray as $key => $v){
if($v == "$userid"){
do something; // if userid is in array
}
}

I need to see if the variable $userid is anywhere in the array but doesnt seem to be working. Is it syntax or the way I am trying to do it.

View Replies !   View Related
Array_push Into Multidimensional Array
I have developed some code to try and push a generated array into an existing array that is pulled from a database then reinsert it. But I dont think my array is being populated. If some one could have a look and tell me where I am going wrong it would be greatly appreciated. Here is my code.

$recievearray = mysql_query("SELECT players FROM users WHERE players='$tnumber");
$recievearrayresults = mysql_fetch_array($recievearray);
$playerarray = unserialize($recievearrayresults['players']);
$playerarraycount = count($playerarray);
array_push($playerarray,array(Player1 => $userid, RegNumber => $playerarraycount+1, Rating => $rec['Rating']));
$newplayerarray = serialize($playerarray);

Then I reinsert it back into the database with a query.

View Replies !   View Related
Was Using Mysql_fetch_assoc, Now Trying Multidimensional Array
I am having trouble getting this loop to do what I would like it to. I need to display information from a multidimensional array in order. The order has already
been sorted in the array using a usort.

How do I display this information the correct way? I previously used mysql_fetch_assoc and returned stored values of win, ties, and losses. Now I have written a function which evaluates each game and determines winners and losers and ties and then puts all the information in an array. Code:

View Replies !   View Related
Multidimensional Array In A Loop
How could you define a multi dimensional array in another multidimensional array.

$pidcounter = 0;
foreach ($invoicenumlist as $key => $value){
foreach ($invoicenumlist[$key] as $key1 => $value1){
$query3 = "SELECT * FROM productid where invoicenum = '$value1'";
$Result3 = mysql_query($query3);
while ($row3=mysql_fetch_array($Result3)){
$productidlist[$key][]=$row3['productid'];
$pidcounter = $pidcounter+1;
}
}
}

View Replies !   View Related
Item In A Multidimensional Array
I have a multidimensional array (I think). It is an array that has arrays inside it. The inside arrays all have the same structure, (qty, product, color, size). How do I count how many items are 'White' * qty? I looked into the php manual and found array_count_values but others say it doesn't work with MD arrays.:confused:

array(
[0] array([0]qty, [1]product, [2] color, [3] size)
[1] array([0]qty, [1]product, [2] color, [3] size)
[2] array([0]qty, [1]product, [2] color, [3] size)
[3] array([0]qty, [1]product, [2] color, [3] size)
[4] array([0]qty, [1]product, [2] color, [3] size)
[5] array([0]qty, [1]product, [2] color, [3] size)
[6] array([0]qty, [1]product, [2] color, [3] size)
...)

View Replies !   View Related
Arrays :: Multidimensional $array
I have a multidimensional $array. (stop me at any point if I'm wrong). Keys are things like [0] => [guid] [link] [title][desc], [1] => [guid] [link] [title][desc] etc. Values have HTML. I array_popped the last item [24] off and exploded out the [desc] key into $new_array. When printed, the array resolves itself into a lovely associative array.

I want to crawl the $new_array's values for a string. Let's say, a username. If the username is in that key's v alue, I want to grab the whole value and explode it some more for db storage. So far all attemps at searching have failed. There is only one key in the array that has the value I want, but it's never in the same place depending on when I am pulling the feed.

View Replies !   View Related
Multidimensional Array Issue
Can I use array_push to push a full array into another array to make a multidimensional array. Here is my code:

$detailsarray = array(Teamname => $userid, Player1 => $userid, Player2 => $Player2);
array_push($playerarray,$detailsarray);

I need this to keep track of players in an event. When the new array is created I update the database and that can then be pulled on another page to see who is in the event.

When a new person signs up then they are just added to the end of the array with there team details. Am I going about this the right way?

View Replies !   View Related
Sorting An Array Problem, (array/string Manipulation)
I have a function that I found on google, that goes through a directory and spits out a directory tree in an array, with arrays inside of arrays, and more and more arrays inside of arrays, depending on how many subdirectories are there.....

Here is a sample "directory tree" it spits out. My problem is wanting to be able to create a new array containing only the paths to all the subdirectories it finds from this array, so it is with array manipulation...

Not all paths are located in the topmost array's values, but some directories are within other subdirectories and so forth.. I'm stumped on how exactly to sort through this array, whether recursively or not to grab all the 'paths' in the array period. Code:

View Replies !   View Related
Sorting Sql Results In An Array Using Things Outside The Array To Sort Them?
I'm using PHP to connect to a database full of place names, and their associated post codes, latitude and longitude on the earth. A user types his or her post code into a form, plus a distance (in miles), and the script looks for other area codes (first half of the post code) within that distance.

I can do that fine, but the results are ordered alphabetically by postcode, and I want to order it by the distance. Problem here, is that the distance isn't part of the array taken from the database, it takes the latitude and longitude of the area it's on in the while loop, and calculates the distance between the user's post code and that one, but it's not part of the array, so I can't sort the array using it.

How can I sort it? Can I add the calculated distances to the array, and sort it using sort()? If yes, how do I add them to the array?

Here's the page, just to explain better what the script does: http://navimaker.org/ed/owain/results.php?postcode=gl15&distance=34
Mess around with the postcode and distance vars.

I'd put the source on here too but I'm doing all this over SSH and can't copy & paste very easily .

View Replies !   View Related

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