Results 1 to 2 of 2
  1. #1
    Join Date
    Jan 2005

    Unanswered: array,insert element

    I have an php array and I want to insert an element with the index -1 and value "none" at first position if possible.Bassicaly I use this code from cakephp
    $customers = $this->Machine->customer->find
       'fields' => array('CUSTOMER_ID', 'CUSTOMER_NAME'),
        'order' => 'CUSTOMER_NAME ASC',
        'recursive' => -1
    I used the array_push() but it did not work as I wanted

  2. #2
    Join Date
    Jun 2007
    You get 2 types of array in PHP. One uses an index going from 0,1,2,3... and the other uses a string as the index. The code you supply is using an associative array (using a string to index the array) but you now seem to want to use a numeric index ie -1 (which is outside the allowed range).

    A quick and dirty solution would be to use the string "-1" as the index. A better solution might be to think about why you even need a -1 entry in your array. It doesn't make much sense to me but then I'm not writing your code

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts