• Categories
    • PHP
    • phpMyAdmin
    • PHPMailer
    • FFMpeg
    • PHPEXcel
    • PHPDoc
    • PHPUnit
    • CakePHP
    • CakePHP 2.0
    • Cake PHP 2.1
    • CakePHP Model
    • Facebook PHP SDK
    • composer-php
    • PHP 7
    • PHP GD
    All Categories
  • About

Need to display only array value in JSON output

phpjson


PHP Snippet 1:

$rows = array();
foreach ($user_details as $row) {
  $rows[] = array_values((array)$row);
}

echo json_encode(array('aaData'=> $rows));

PHP Snippet 2:

{"aaData": [
    ["31","Elankeeran","[email protected]","0","1234"],
    ["33","Elan","[email protected]","1",""]
]}

PHP Snippet 3:

echo '{"aaData":'.json_encode(array_values($user_details)).'}';

PHP Snippet 4:

obj.aaData[0].name;
// Elankeeran

obj.aaData[0].email;
// [email protected]

Related Snippets

Fatal error: Uncaught TypeError: count(): Argument #1 ($var) must be of type Countable|array, null given in

Undefined Array Key error when uploading image on php

PHP 8.1: strftime() is deprecated

Laravel 5 issue with wherePivot

Display Brand Name Above Product Title in Woocommerce Cart, Checkout Page, Orders and Email Notification

Laravel Passport - Not able to get token string in response?

Webscraping Symfony/Panther: Can't get HTML

auth pages not getting css in laravel

get data-value with variable value

Utf8 encoding issue with Laravel

SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'name' cannot be null

How to get multiple values with same key from an array PHP

Timber: Single post pagination does not work (wp_link_pages)

How to add class name to an existing tag in php

HTTP Range requests with php for Video Embedding for solving going to specific time in video (seek bar not work)

About Contact Privacy policy Terms and conditions