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

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -