Answers for "php print array in console"

PHP
13

print array php

<?php
$a = array ('a' => 'apple', 'b' => 'banana', 'c' => array ('x', 'y', 'z'));
echo "<pre>";
print_r ($a);
echo "</pre>";
?>
  
Output:

Array
(
    [a] => apple
    [b] => banana
    [c] => Array
        (
            [0] => x
            [1] => y
            [2] => z
        )
)
Posted by: Guest on February-26-2020
3

php array to console

function console_log( $data ){
  echo '<script>';
  echo 'console.log('. json_encode( $data ) .')';
  echo '</script>';
}

Usage:
$myvar = array(1,2,3);
console_log( $myvar ); // [1,2,3]
Posted by: Guest on March-13-2021
1

php echo and array to consle

echo "<script>console.log('" . json_encode($data) . "');</script>";
Posted by: Guest on December-07-2020
1

php echo an array to console

echo "<script>console.log('" . json_encode($data) . "');</script>";
Posted by: Guest on December-07-2020

Browse Popular Code Answers by Language