PHP Applications
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsPHP RelatedPHP Applications

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
  #1  
Old November 22nd, 2008, 06:21 AM
amber.long83 amber.long83 is offline
Contributing User
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Nov 2008
Posts: 32 amber.long83 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 10 h 6 m 47 sec
Reputation Power: 2
Any way to reindex the php array?

hi guys

i am just looking for any simple php function or any inbuilt php function which reindex the php keys of an array?

for example, I have an array
PHP Code:
 $str_name = array(0=>"a"1=>"b"2=>"c"5=>"d"10="e"); 


I want to make the keys of all element in sequence so the output should look something like

PHP Code:
array(0=>"a"1=>"b"2=>"c"3=>"d"4="e"); 

Reply With Quote
  #2  
Old November 22nd, 2008, 06:21 PM
IAmALlama IAmALlama is offline
Me
Click here for more information. Click here for more information
Click here for more information
 
Join Date: Apr 2007
Location: Seattle, WA
Posts: 1,937 IAmALlama User rank is Private First Class (20 - 50 Reputation Level)IAmALlama User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 1 Week 5 Days 1 h 54 m 18 sec
Reputation Power: 4
array_merge() will re-index an array with numeric values or sort() if you don't mind changing the order of the items to alphabetical/numerical order.

Reply With Quote
  #3  
Old November 29th, 2008, 12:21 AM
amber.long83 amber.long83 is offline
Contributing User
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Nov 2008
Posts: 32 amber.long83 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 10 h 6 m 47 sec
Reputation Power: 2
Quote:
Originally Posted by IAmALlama
array_merge() will re-index an array with numeric values or sort() if you don't mind changing the order of the items to alphabetical/numerical order.


Thanks for the reply but array merge required two array. here in my case i have only one array and want to re-index the key.

Reply With Quote
  #4  
Old March 21st, 2009, 04:48 PM
bluephoenix's Avatar
bluephoenix bluephoenix is offline
Levelheaded Curmudgeon
Codewalkers Novice (500 - 999 posts)
 
Join Date: Apr 2007
Location: Syracuse, NY
Posts: 508 bluephoenix User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 h 24 m 56 sec
Reputation Power: 3
Send a message via AIM to bluephoenix
amber.long83--

No, array_merge WILL accept 1 parameter.

When you use array_merge, PHP internally creates an empty array to start and then merges the elements of the arrays provided to array_merge. If only one array is given, then that's all there is to merge into the empty array.

However, probably the easiest and most intuitive way to do what you're looking for is to use array_values.
__________________
www.saltcitytech.com
Beware of bugs in the above code; I have only proved it correct, not tried it. -- Donald Knuth
Remember kids, it's mysql_real_escape_string, not mysql_fake_escape_string.

Last edited by bluephoenix : March 21st, 2009 at 04:55 PM.

Reply With Quote
  #5  
Old June 22nd, 2009, 05:55 AM
amber.long83 amber.long83 is offline
Contributing User
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Nov 2008
Posts: 32 amber.long83 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 10 h 6 m 47 sec
Reputation Power: 2
thanks man

thanks bluephoenix

array_values is the trick for my requiredment

thanks again


Quote:
Originally Posted by bluephoenix
amber.long83--

No, array_merge WILL accept 1 parameter.

When you use array_merge, PHP internally creates an empty array to start and then merges the elements of the arrays provided to array_merge. If only one array is given, then that's all there is to merge into the empty array.

However, probably the easiest and most intuitive way to do what you're looking for is to use array_values.

Reply With Quote
Reply

Viewing: Codewalkers ForumsPHP RelatedPHP Applications > Any way to reindex the php array?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump




 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

Request Your Free Technology Downloads!
 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

Request Your Free Technology Downloads!
 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

Request Your Free Technology Downloads!
 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

Request Your Free Technology Downloads!
 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

Request Your Free Technology Downloads!
 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 




© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 5 Hosted by Hostway
For more Enterprise Application Development news, visit eWeek