window.ad_products = [
<?php
$arLength = count( $arResult['ITEMS']['AnDelCanBuy'] );
for( $i = 0 ; $i < $arLength ; $i++ ) {
echo "{ id: " . $arResult['ITEMS']['AnDelCanBuy'][$i]['PRODUCT_ID'] . ", number: " . $arResult['ITEMS']['AnDelCanBuy'][$i]['QUANTITY'] . " }" . ( $i === $arLength - 1 ? "" : ", " );
}
?>
];
original_json = '{"payed":"[[6,1,37,1],[5,1,37,1],[3,1,37,1]]"}';
result_object = JSON.parse( original_json );
array_of_arrays = JSON.parse( result_object.payed );
console.log(arr_of_arrs_lol); // Array [ Array[4], Array[4], Array[4] ]
console.log(arr_of_arrs_lol[0]); // Array [ 6, 1, 37, 1 ]
console.log(arr_of_arrs_lol[0][0]); // 6
<?php
$arResult = array(
array(
"PRODUCT_ID" => 1,
"QUANTITY" => 1
),
array(
"PRODUCT_ID" => 2,
"QUANTITY" => 1
)
);
$arLength = count( $arResult );
?>
<script type="text/javascript">
window.some_nice_products_we_have_here = [
<?php
for( $i = 0 ; $i < $arLength ; $i++ ) {
echo "{ id: " . $arResult[$i]['PRODUCT_ID'] . ", number: " . $arResult[$i]['QUANTITY'] . " }" . ( $i === $arLength - 1 ? "" : ", " );
}
?>
];
console.log(JSON.stringify(some_nice_products_we_have_here, null, 2));
</script>
<?php
$arResult = array(
array(
"PRODUCT_ID" => 1,
"QUANTITY" => 1
),
array(
"PRODUCT_ID" => 2,
"QUANTITY" => 1
)
);
$arLength = count( $arResult );
?>
<script type="text/javascript">
window.some_nice_products_we_have_here = [
<?php
for( $i = 0 ; $i < $arLength ; $i++ ) {
echo "{ id: \"" . $arResult[$i]['PRODUCT_ID'] . "\", number: \"" . $arResult[$i]['QUANTITY'] . "\" }" . ( $i === $arLength - 1 ? "" : ", " );
}
?>
];
console.log(JSON.stringify(some_nice_products_we_have_here, null, 2));
</script>
"{"payed":[[6,1,37,1],[5,1,37,1],[3,1,37,1]]}"
"{"payed":"[[6,1,37,1],[5,1,37,1],[3,1,37,1]]"}"
А еще есть такая замечательная книжка