0

Hello I would like to sort my 3d array by the key "Value" then echo out the response. This is for a fraction game where people are suppose to place the fractions in order i have the fractions being generated but I need to echo out the array part by part like echo $data[0].

 $data = array( array('Value' => $even, 'PartA' => $Part1A, 'PartB' => $Part1B), array('Value' => $even2, 'PartA' => $Part2A, 'PartB' => $Part2B), array('Value' => $even3, 'PartA' => $Part3A, 'PartB' => $Part3B), array('Value' => $even4, 'PartA' => $Part4A, 'PartB' => $Part4B), array('Value' => $even5, 'PartA' => $Part5A, 'PartB' => $Part5B) ); // function makeSortFunction($field) // { // $code = "return strnatcmp(\$a['$field'], \$b['$field']);"; // return create_function('$a,$b', $code); // } // usort($data, makeSortFunction('Value')); sort($data); var_dump($data); echo "test" . $data[0][0] . "test"; 
1
  • this is only 2d unless the parts are arrays Commented May 25, 2014 at 0:24

2 Answers 2

1

I think the best way to echo an arrays is

 echo print_r($array, true); 
Sign up to request clarification or add additional context in comments.

Comments

0

Try this.

foreach($data as $v){ foreach($v as $v2){ echo $v2; } } 

1 Comment

If it truly is 3d, you need another for loop in there. In addition, if not all the attributes are arrays there needs to be a conditional to skip particular attributes

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.