• 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

Destroy session upon refresh

Laravel : How to Create Dropdown to Select FOREIGN KEY from Other Table?

Use same method for inertia response and json response Laravel Jetstream

How to submit a form when page loads using JavaScript?

PHPMetrics option --excluded-dirs="myfolder" : myfolder dir is not excluded within docker

Docker & Laravel : configure: error: Package requirements (oniguruma) were not met

Respond with status code 401 on authentication failure using Laravel and Passport?

The difference when using if statement true === something() vs something() === true [duplicate]

How to separate letters and digits from a string in php

Google Gmail API - How to login programatically?

Laravel whole batch is cancelled if one Job fails

Not able to override collapsible.js in magento 2

How to get AJAX to post on second page?

Do I need to install `fxp/composer-asset-plugin` if I'm not doing front-end development

Explain how this array transposing and flattening function works

About Contact Privacy policy Terms and conditions