Lets say we have an array:
$array[]='apples';
$array[]='orange';
$array[]='lemon';
echo $array[1]; // orange
Now, lets say we want to insert "grape", between apples and orange. How
do we do that?
I have some memory of seeing a php shortcut to do this, but I can't find
it now.
Also, I see there are a number of custom php functions for sorting
(kudos on some of these). Is there a way to write your own sorting function?
Jeff 6 1515
On 16 Jun, 14:45, Jeff <jeff@spam_me_not.comwrote:
* *Lets say we have an array:
$array[]='apples';
$array[]='orange';
$array[]='lemon';
echo $array[1]; // orange
Now, lets say we want to insert "grape", between apples and orange. How
do we do that?
I have some memory of seeing a php shortcut to do this, but I can't find
it now.
* *Also, I see there are a number of custom php functions for sorting
(kudos on some of these). Is there a way to write your own sorting function?
* *Jeff
You are looking for array_splice() http://uk2.php.net/manual/en/function.array-splice.php
But you could have scanned the list of array functions in the manual
just as easily as I could.
..oO(Jeff)
Lets say we have an array:
$array[]='apples'; $array[]='orange'; $array[]='lemon';
echo $array[1]; // orange
Now, lets say we want to insert "grape", between apples and orange. How do we do that?
You just add it like above and then sort the array.
>I have some memory of seeing a php shortcut to do this, but I can't find it now.
Also, I see there are a number of custom php functions for sorting (kudos on some of these). Is there a way to write your own sorting function?
usort()
Micha
On 16 Jun, 15:30, Michael Fesser <neti...@gmx.dewrote:
.oO(Jeff)
* Lets say we have an array:
$array[]='apples';
$array[]='orange';
$array[]='lemon';
echo $array[1]; // orange
Now, lets say we want to insert "grape", between apples and orange. How
do we do that?
You just add it like above and then sort the array.
If he did what you poposed, he'd get
apples
grape
lemon
orange
But he wanted
apples
grape
orange
lemon
So array_splice is the way to do it.
Captain Paralytic wrote:
On 16 Jun, 14:45, Jeff <jeff@spam_me_not.comwrote:
> Lets say we have an array:
$array[]='apples'; $array[]='orange'; $array[]='lemon';
echo $array[1]; // orange
Now, lets say we want to insert "grape", between apples and orange. How do we do that?
I have some memory of seeing a php shortcut to do this, but I can't find it now.
Also, I see there are a number of custom php functions for sorting (kudos on some of these). Is there a way to write your own sorting function?
Jeff
You are looking for array_splice() http://uk2.php.net/manual/en/function.array-splice.php
But you could have scanned the list of array functions in the manual
just as easily as I could.
Yes, I see splice with a 0 length.
I have a hard time with the manual.
If I start at the index page ( http://www.php.net/manual/en/) -type ->
array
I get this page: http://www.php.net/manual/en/language.types.array.php
Which has none of the array functions.
If I go: index->functions, I can't find the internal function list. I
know it's there but I can't find it.
The keyword search works fine, but I don't know the keywords. I
suppose I'll have to bookmark the appropriate pages as I find them! I
just don't seem to be able to figure out how to navigate the manual.
I don't wish to annoy you with easy questions, my apologies.
Jeff
In our last episode, <Mb******************************@earthlink.com> , the
lovely and talented Jeff broadcast on comp.lang.php:
I have a hard time with the manual.
If I start at the index page (http://www.php.net/manual/en/) -type ->
array
What exactly do you mean by "->"? The link to function index is at the
bottom of the contents. It is alphabetical and that makes the array
functions not too far down.
--
Lars Eighner <http://larseighner.com/ us****@larseighner.com
Countdown: 217 days to go.
Lars Eighner wrote:
In our last episode, <Mb******************************@earthlink.com> , the
lovely and talented Jeff broadcast on comp.lang.php:
>I have a hard time with the manual.
>If I start at the index page (http://www.php.net/manual/en/) -type -> array
What exactly do you mean by "->"?
Choose / select , in other words, go to.
The link to function index is at the
bottom of the contents.
Thanks, I see it now! Last link in the appendix! That will make life
easier!
Jeff
It is alphabetical and that makes the array
functions not too far down.
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: jeff |
last post by:
how do you convert form byte to Int32 while retaining the binary
value of the byte array
|
by: Raptor |
last post by:
Hi,
I'm quite new to MySQL and quite impressed by its feature set. I've
also been looking at Interbase and it has a feature that allows a
multidimensional array to be stored in a single field. ...
|
by: dof |
last post by:
I'm trying the following and having problems. I get errors on the array declaration lines. Something about an array must have at least one element. Thanks in advance. D
#include stuff
....
...
|
by: Benjamin M. Stocks |
last post by:
Hello all,
I've heard differing opinions on this and would like a definitive
answer on this once and for all. If I have an array of 4 1-byte values
where index 0 is the least signficant byte of a...
|
by: wlevine |
last post by:
Can someone give me an example of how to construct an array of objects?
for example, I have:
function objFacility(id,name,adr,city,state,zip)
{
this.id = id
this.name=name
this.adr=adr...
|
by: Michael |
last post by:
Hi,
I am trying to pass a function an array of strings, but I am having trouble
getting the indexing to index the strings rather than the individual
characters of one of the strings.
I have...
|
by: JDT |
last post by:
Hi,
It seems that using floats as the first tupelo for an STL map (shown
below) can cause problems but I don't remember what the problems were.
Is it common practice to use a structure like...
|
by: harvey |
last post by:
What is the easiest way to get both the last item name and last item
value from an associative array?
I can get the value with array_pop() but can't see anything similar
for the item's name.
...
|
by: fgh.vbn.rty |
last post by:
I am frequently using maps like the following:
map<string, map<int, vector< pair<int, int m1;
map<int, map<string, map<int, int m2;
This can be a little difficult to maintain if another coder...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |