Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 570441
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T13:24:06+00:00 2026-05-13T13:24:06+00:00

Using CakePHP (On PHP 5.2.6) I do a list query on a table which

  • 0

Using CakePHP (On PHP 5.2.6) I do a list query on a table which returns an array like:

Array
(

[0] => None
[3] => Value 1
[5] => Value 2

)

Since it’s not a sequential array json_encode() encodes it to an object instead of a JSON array which I need for filling a Jeditable Select.

PHP 5.2.6 does not support any additional parameters, so I can’t force it to create an JSON encoded array.

My question, does anyone know how I can solve this problem in a clean way?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T13:24:07+00:00Added an answer on May 13, 2026 at 1:24 pm

    see http://docs.php.net/array_values :

    array_values() returns all the values from the input array and indexes numerically the array.

    e.g.

    $a = array(
      0 => 'None',
      3 => 'Value 1',
      5 => 'Value 2'
    );
    $x = array_values($a);
    print_r($x);
    echo json_encode($x);
    

    prints

    Array
    (
        [0] => None
        [1] => Value 1
        [2] => Value 2
    )
    ["None","Value 1","Value 2"]
    

    edit: Javascript arrays can’t have gaps. You’d have to fill the missing elements with e.g. NULL.

    $a = array(
      0 => 'None',
      3 => 'Value 1',
      5 => 'Value 2'
    );
    
    $na = array_pad(array(), max(array_keys($a)), null);
    $a += $na;
    ksort($a);
    echo json_encode($a);
    

    prints ["None",null,null,"Value 1",null,"Value 2"]

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using CakePHP. I created an external class which is not a model
what would be the efficient way of saving the following array using php (cakephp)?
I'm using CakePHP 2.0. I have 2 models/controllers (Category/Coupon): // File: Model/Coupon.php // Table
I have a PHP application using CakePHP. I need to present a table showing
I am using cakephp with php, I have table with field id having data
I have a PHP SOAP web service, using CakePHP, which is returning a variable
I am using cakephp and creating a form <?php echo $form->create('User', array('action' => 'cancel'));?>
I'm using cakephp 2.1.3 and I have a table Ingredients and a table IngredientAliases
i am using cakephp 1.3 ...it was working like charm in server ,i copied
I am using cakephp. I am trying to use httpsocket to get information. <?php

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.