I want to send the value to jquery-variable in new format, i am using nested foreach loop here is my code:
foreach($names as $key1 => $desc1) {
$arr_names[] = $names;
$details = get_details( $key1 );
if ( is_array( $states ) ) {
foreach($details as $key2 => $desc2) {
$title[] = $key2;
$value[] = $desc2;
}
}
}
echo "<input type='hidden' id='storageElement' data-storectrystts='".json_encode($namdetailsArray)."'>";
Right now, i can get this:
Array
(
[0] => Sam
[1] => Ben
[2] => John
[0] => Age
[1] => Place
[2] => Height
[3] => Weight
[4] => Year
[5] => Salary
[0] => 30
[1] => AU
[2] => 6
[3] => 150
[4] => First
[5] => 50000
)
I need to send value in this format through data-storectrystts='".json_encode($namdetailsArray).":
'Sam' => [
['Age', '30'],
['Place', 'AU']],
'Ben' => [
['Height', '6'],
['Weight', '150']],
'John' => [
['Year', 'First'],
['Salary', '50000']]
Update
//if we use print_r($namdetailsArray); then everything is fine
Array
(
[Sam] => Array
(
[0] => Array
(
[0] => Age
[1] => 30
)
[1] => Array
(
[0] => Place
[1] => AU
)
)
[Ben] => Array
(
[0] => Array
(
[0] => Height
[1] => 6
)
[1] => Array
(
[0] => Weight
[1] => 150
)
)
[John] => Array
(
[0] => Array
(
[0] => Year
[1] => First
)
[1] => Array
(
[0] => Salary
[1] => 50000
)
)
[Derek] => Array
(
[0] => Array
(
[0] => tax's cal
[1] => 100
)
[1] => Array
(
[0] => distance
[1] => 5
)
)
)
//if we use echo json_encode($namdetailsArray) then everything is fine
{"Sam" => [
["Age", "30"],
["Place", "AU"]],
"Ben" => [
["Height", "6"],
["Weight", "150"]],
"John" => [
["Year", "First"],
["Salary", "50000"]],
"Derek" => [
["tax's cal", "100"],
["distance", "5"]]}
/*but if we use
echo "<input type='hidden' id='storageElement' data-storectrystts='".json_encode($namdetailsArray)."'>";
echo '<div id="availhai"></div>';
var cSttArry = $("#storageElement").data('storectrystts');
$("#availhai").html(cSttArry);
then it is not showing anything after word "tax" */
{"Sam" => [
["Age", "30"],
["Place", "AU"]],
"Ben" => [
["Height", "6"],
["Weight", "150"]],
"John" => [
["Year", "First"],
["Salary", "50000"]],
"Derek" => [
["tax