PHP Specials foreach multidimensional array -


i got array this

$specials = array( 1 => array('word' => array('first', 'two', 'three'), 'digit' => array(1,2,3)),                    2 => array('word' => array('four','five', 'six'), 'digit' => array(4,5,6)),                     3 => array('word' => array('seven', 'eight', 'nine'), 'digit' => array(7,8,9)),                    4 => array('word' => array('ten','eleven', 'twelve'), 'digit' => array(10,11,12))                     ); 

and why got foreach 3 times this

foreach($specials  $val) {     foreach($val $valdata) {         foreach($valdata $value) {             echo $value.'<br/>';         }     } }  

but how loop or foreach correctly , index name ?

echo $value['word']; echo $value['digit']; 

i got error warning if echo $value['digit']

warning: illegal string offset 'digit' in ~/public_html/test/array.php on line 58 

i need output different html , css each value

<div class="digit"><?=$value['digit']?></div> <div class="word"><?=$value['word']?></div>

foreach($specials  $val) {     foreach($val $key => $valdata) {         // $key either 'word' or 'digit'         foreach($valdata $value) {             echo "<div class='$key'>$value</div>";         }     } }  

Comments

Popular posts from this blog

node.js - Using Node without global install -

How to access a php class file from PHPFox framework into javascript code written in simple HTML file? -

java - Null response to php query in android, even though php works properly -