If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > PHP > array,insert element

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-15-10, 08:55
dimis2500 dimis2500 is offline
Registered User
 
Join Date: Jan 2005
Posts: 362
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
Code:
$customers = $this->Machine->customer->find
             (
    'list',
   array
   (
   '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
Reply With Quote
  #2 (permalink)  
Old 01-15-10, 09:07
mike_bike_kite mike_bike_kite is offline
vaguely human
 
Join Date: Jun 2007
Location: London
Posts: 2,519
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
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On