0

I want to search a multidimensional Array for a specific field, then reference that variable in an Array. I have used one Array for this example:

$cars = array
(
array("Volvo",$vr,96),
array("BMW",60,59),
array("Toyota",110,100)
);

$vr=$cars[1][2];
echo $cars[0][1];

How do I do that?

Or this?

$cars = array
(
array("Volvo",10,96),
array("BMW",60,59),
array("Toyota",110,100)
);


$graph = array
(
array("sept", $cars[0][1]),
array("oct", 20),
array("nov", 35)
);
user1721230
  • 317
  • 1
  • 6
  • 19
  • What you're asking is not clear. Please elaborate. What kind of search are you performing on what source and what for? – Armel Larcier Jan 05 '14 at 14:56
  • The above is just a more straightforward version of what I want to do. I want to search a multidimensional Array $cars[0][1] and use that number in a another multidimensional Array either as a variable or directly. – user1721230 Jan 05 '14 at 15:00
  • In the 2nd example the 2nd Array builds a graph using phplot – user1721230 Jan 05 '14 at 15:07
  • does that `$vr=$cars[1][2];` in same location( `SAME KEY` ) in your array ? – underscore Jan 05 '14 at 15:09
  • I guess the question really is can you use a variable in a multidimensional Array? – user1721230 Jan 05 '14 at 15:12
  • @samitha not sure what you mean? If the above examples are possible, then my actual code should be fine. Do you know if a variable can be used in a multidimensional Array? Cuz I reckon thats the bones of it – user1721230 Jan 05 '14 at 15:17
  • may be duplicate of http://stackoverflow.com/questions/6661530/php-multi-dimensional-array-search – Kumar V Jan 05 '14 at 15:19
  • I dont think so from what I understand. I'm accessing a value in a multi Array then using that value in another multi Array – user1721230 Jan 05 '14 at 15:24

1 Answers1

0

Yes is the answer. I know it must seem like a very newbie question but hopefully this will hep someone in the future:

$cars1 = array
(
array("Volvo",3,96),
array("BMW",60,59),
array("Toyota",110,100),

);

$vr=$cars1[1][1];

$cars = array
(
array("Volvo",$vr,96),
array("BMW",60,59),
array("Toyota",110,100),

);

echo $cars[0][1];

Correct me if I am wrong but I guess it has something to do with the order of the PHP. The Array needed the variable before the Array was made.

user1721230
  • 317
  • 1
  • 6
  • 19