I would like to Explode a string into an array that does not begin at
0 but I can't get it to work.
For example: $MyInfo = array(1 =27,68,31,19,40);
will result in $MyInfo[1] = 27 ... $MyInfo[5] = 40
But, I'd like to process a string: "27,68,31,19,40" such that it would
get the same result.
I tried:
$MyString = "27,68,31,19,40"
$MyInfo = array(1 =$MyString);
But that doesn't work.
I also tried:
$MyString = "27,68,31,19,40"
$MyInfo = array(1 =explode($MyString, ","));
That doesn't do it either.
How can this be done? 8 1939
On 11 Feb, 16:02, Jack <ironwoodcan...@gmail.comwrote:
I would like to Explode a string into an array that does not begin at
0 but I can't get it to work.
For example: $MyInfo = array(1 =27,68,31,19,40);
will result in $MyInfo[1] = 27 ... $MyInfo[5] = 40
But, I'd like to process a string: "27,68,31,19,40" such that it would
get the same result.
I tried:
$MyString = "27,68,31,19,40"
$MyInfo = array(1 =$MyString);
But that doesn't work.
I also tried:
$MyString = "27,68,31,19,40"
$MyInfo = array(1 =explode($MyString, ","));
That doesn't do it either.
How can this be done?
It might help if you tell us why you feel the need to do this.
On Mon, 11 Feb 2008 17:02:36 +0100, Jack <ir************@gmail.comwrote:
I would like to Explode a string into an array that does not begin at
0 but I can't get it to work.
For example: $MyInfo = array(1 =27,68,31,19,40);
will result in $MyInfo[1] = 27 ... $MyInfo[5] = 40
But, I'd like to process a string: "27,68,31,19,40" such that it would
get the same result.
I tried:
$MyString = "27,68,31,19,40"
$MyInfo = array(1 =$MyString);
But that doesn't work.
I also tried:
$MyString = "27,68,31,19,40"
$MyInfo = array(1 =explode($MyString, ","));
That doesn't do it either.
How can this be done?
You shouldn't want it, but here you go:
Easiest:
<?php
$MyString = "27,68,31,19,40"
$MyArray = explode(',', '0,'.$MyString);
unset($MyArray[0]);
?>
More verbose:
<?php
$MyString = "27,68,31,19,40"
$MyArray = explode(',',$MyString);
array_unshift($MyArray,null);
unset($MyArray[0]);
?>
--
Rik Wasmus
On Mon, 11 Feb 2008 08:05:47 -0800 (PST), Captain Paralytic
<pa**********@yahoo.comwrote:
>On 11 Feb, 16:02, Jack <ironwoodcan...@gmail.comwrote:
>I would like to Explode a string into an array that does not begin at 0 but I can't get it to work.
For example: $MyInfo = array(1 =27,68,31,19,40); will result in $MyInfo[1] = 27 ... $MyInfo[5] = 40
But, I'd like to process a string: "27,68,31,19,40" such that it would get the same result.
I tried: $MyString = "27,68,31,19,40" $MyInfo = array(1 =$MyString); But that doesn't work.
I also tried: $MyString = "27,68,31,19,40" $MyInfo = array(1 =explode($MyString, ",")); That doesn't do it either.
How can this be done?
It might help if you tell us why you feel the need to do this.
How does that impact the the issue of "how can this be done" ?
On Mon, 11 Feb 2008 17:13:09 +0100, Jack <ir************@gmail.comwrote:
On Mon, 11 Feb 2008 08:05:47 -0800 (PST), Captain Paralytic
<pa**********@yahoo.comwrote:
>On 11 Feb, 16:02, Jack <ironwoodcan...@gmail.comwrote:
>>I would like to Explode a string into an array that does not begin at 0 but I can't get it to work.
For example: $MyInfo = array(1 =27,68,31,19,40); will result in $MyInfo[1] = 27 ... $MyInfo[5] = 40
But, I'd like to process a string: "27,68,31,19,40" such that it would get the same result.
I tried: $MyString = "27,68,31,19,40" $MyInfo = array(1 =$MyString); But that doesn't work.
I also tried: $MyString = "27,68,31,19,40" $MyInfo = array(1 =explode($MyString, ",")); That doesn't do it either.
How can this be done?
It might help if you tell us why you feel the need to do this.
How does that impact the the issue of "how can this be done" ?
We might offer a better solution to the problem then one that will throw
other/fellow/future coders off balance.
--
Rik Wasmus
..oO(Jack)
>On Mon, 11 Feb 2008 08:05:47 -0800 (PST), Captain Paralytic <pa**********@yahoo.comwrote:
>>It might help if you tell us why you feel the need to do this.
How does that impact the the issue of "how can this be done" ?
It looks as if you just want the indexing to start at 1 instead of 0.
But usually this is not necessary, since you can always adjust it as
necessary when accessing the array, for example by giving another start
value for a loop or by using something like $yourArray[$yourIndex-1].
Arrays in PHP are always zero-based, many array handling functions
expect or return them this way.
So, the question "Why?" is valid.
Micha
On Feb 11, 11:13 am, Jack <ironwoodcan...@gmail.comwrote:
On Mon, 11 Feb 2008 08:05:47 -0800 (PST), Captain Paralytic
<paul_laut...@yahoo.comwrote:
On 11 Feb, 16:02, Jack <ironwoodcan...@gmail.comwrote:
I would like to Explode a string into an array that does not begin at
0 but I can't get it to work.
For example: $MyInfo = array(1 =27,68,31,19,40);
will result in $MyInfo[1] = 27 ... $MyInfo[5] = 40
But, I'd like to process a string: "27,68,31,19,40" such that it would
get the same result.
I tried:
$MyString = "27,68,31,19,40"
$MyInfo = array(1 =$MyString);
But that doesn't work.
I also tried:
$MyString = "27,68,31,19,40"
$MyInfo = array(1 =explode($MyString, ","));
That doesn't do it either.
How can this be done?
It might help if you tell us why you feel the need to do this.
How does that impact the the issue of "how can this be done" ?
Because, according to "How To Ask Questions the Smart Way" you should
describe the /goal/ you are after, not the intermediate step you might
be stuck on:
<http://catb.org/~esr/faqs/smart-questions.html#goal>
On Feb 11, 6:02 pm, Jack <ironwoodcan...@gmail.comwrote:
I would like to Explode a string into an array that does not begin at
0 but I can't get it to work.
For example: $MyInfo = array(1 =27,68,31,19,40);
will result in $MyInfo[1] = 27 ... $MyInfo[5] = 40
But, I'd like to process a string: "27,68,31,19,40" such that it would
get the same result.
I tried:
$MyString = "27,68,31,19,40"
$MyInfo = array(1 =$MyString);
But that doesn't work.
I also tried:
$MyString = "27,68,31,19,40"
$MyInfo = array(1 =explode($MyString, ","));
That doesn't do it either.
How can this be done?
-------------
<?
$MyString = "27,68,31,19,40";
$MyArray=explode(",",$MyString);
for($a=0;$a<sizeof($MyArray);$a++)
echo $MyArray[$a] . " ";
?>
On Feb 12, 12:12 pm, Betikci Boris <pard...@gmail.comwrote:
On Feb 11, 6:02 pm, Jack <ironwoodcan...@gmail.comwrote:
I would like to Explode a string into an array that does not begin at
0 but I can't get it to work.
For example: $MyInfo = array(1 =27,68,31,19,40);
will result in $MyInfo[1] = 27 ... $MyInfo[5] = 40
But, I'd like to process a string: "27,68,31,19,40" such that it would
get the same result.
I tried:
$MyString = "27,68,31,19,40"
$MyInfo = array(1 =$MyString);
But that doesn't work.
I also tried:
$MyString = "27,68,31,19,40"
$MyInfo = array(1 =explode($MyString, ","));
That doesn't do it either.
How can this be done?
-------------
<?
$MyString = "27,68,31,19,40";
$MyArray=explode(",",$MyString);
for($a=0;$a<sizeof($MyArray);$a++)
echo $MyArray[$a] . " ";
?>
<?
$MyString = "27,68,31,19,40";
$MyArray=explode(",",$MyString);
for($a=0;$a<sizeof($MyArray);$a++)
$MyTempArray[$a+1]=$MyArray[$a];
for($a=0;$a<sizeof($MyArray);$a++)
$MyArray[$a]=$MyTempArray[$a];
echo $MyArray[1] //Output would be 27;
?> This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Stijn Goris |
last post by:
Hi all,
$ttt = array();
$ttt = explode("-", "test-niet");
echo "$ttt | $ttt<br>";
Should give
test | niet
but gives
|
by: William Krick |
last post by:
I have a string containing concatenated ascii "records" that are each
terminated by '\n'.
For testing purposes, I construct sample data like this...
$mystring =...
|
by: voipcanada |
last post by:
Here is the sample text (( http://starkom.com/bill20050820_000000 ))
wanted to know if there is some other function like explode to split
the = sign in each array
|
by: frizzle |
last post by:
Hi there,
i have a site with fake folders & files.
htaccess rewrites everything to index.php?vars
now in index.php i decide what file to include with a switch/case
statement.
to define where...
|
by: Joe |
last post by:
I have a 'random quotes' plugin that I use which reads tab delimited
quotes from multiple text files in a directory, and then randomly
displays one. Each text file contains multiple lines, each...
|
by: k04jg02 |
last post by:
Python has a nifty operator that will take a container and pass its
elements as function parameters. In Python you can make a list like
so:
x =
Then you can say:
f(*x)
|
by: rvimalram |
last post by:
Hi all,
I have a created a multidimesional array,what i need is to traverse that array and return the value of the array in the particular page
the array is
$one=array("one" =>"Text1");...
|
by: tolkienarda |
last post by:
hi everyone
i am getting a bunch of values from a form via post all of the information that this question deals with is from series of check boxes below is the code that creates the check boxes...
|
by: sathyashrayan |
last post by:
Dear group,
The function to be used as follows:
$links = "http://www.campaignindia.in/feature/analysis";
$tag1 = '<div class=feature-wrapper>';
$tag2 = '<h1><a href';
$tag3 = "</a>";
$op =...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
| |