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

  • Home
  • SEARCH
  • 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

Ask A Question

Stats

  • Questions 287k
  • Answers 287k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer (E(F|G)?) will always be caught as group 3. The numbering… May 13, 2026 at 5:10 pm
  • Editorial Team
    Editorial Team added an answer It sounds as if the import runs on the UI… May 13, 2026 at 5:10 pm
  • Editorial Team
    Editorial Team added an answer Yes. Typing Unicode at the console is always problematic and… May 13, 2026 at 5:10 pm

Related Questions

I have a login screen that I force to be ssl, so like this:
I made a blog database and created some tables in it. I have wriTten
I'm developing a CakePHP site for which I've just enabled VAS authentication using a
I am using cakephp framework to build my application. I want that, whenever a
CakePHP makes heavy use of associative arrays for passing large numbers of parameters to

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.