php - Output array so it can be used as value for data attribute -
i have array in php looping through content.
when echoed, results of array variable $myarray
looks below
array( [0] => abc [1] => def [2] => ghi [3] => jkl ) array( [0] => mno [1] => 123a [2] => 123b [3] => 123c ) array( [0] => orange [1] => yellow [2] => green [3] => blue )
but when pass html data element using
data-results = "$myarray"
i a
notice: array string conversion
error.
how can passed 1 array html data element?
if want print array string equivalent, can use:
$stringarray = print_r($array, true); echo $stringarray;
if wish print json string, can use:
$array = array('a', 'b', 'c'); echo json_encode($array);
Comments
Post a Comment