php - Extraing data from json array and separate according to type -


so trying extract information json array using json_decode($result,true). background here there php script getting information database , sending data me json_encoded result.

using print_r($json) following

array ( [result] => 1 [message] => query successful [data] => query output [0] => array     (         //several values          [test] => test         [example] => catcatcat         [choice2] => b      ) [1] => array      [test]=> test //etc.... 

i understand can use simple loop stuff display or in case used

for($i=0;$i<=count($json); $i++){     echo $json[$i]['test'];     //etc etc } 

and display value. cant figure out how send html page output list.

i trying display following

  1. test catcatcat b
  2. test etc etc

--this may separate question me learn want know if it's possible break down array , send html radio input , turn value choose from.

your json result mixture of 1st level elements , sub-arrays, you'll need filter those.

use foreach loop output radio buttons:

foreach($json $current) {     if(!is_array($current))         continue; // skip top level properties aren't sub arrays      echo '<input type="radio" name="yourradio" value="' . $current['choice2'] . '"> ' . $current['test'] . ' ' . $current['example']; } 

the value of radio button , labels you, that's general idea.


Comments

Popular posts from this blog

php - SPIP: From Tag directly to an article -

jquery - isAjaxRequest always return false -

ruby on rails - In a controller spec, how to find a specific tag in the generated view? -