Re: [PHP] array within array

2007-02-12 Thread Jim Lucas

Steven Macintyre wrote:

Heya,

Thanks for the reply ... 


$articles = split(Section break, $mystring);
foreach ($articles as $value) {
$newsarray[] = split(br, $value);
}

print_r($newsarray);
foreach ($newsarray as $value1) {
echo b.$value1[0]./b;
echo brbr;
echo $value1[1];


this $value1[1]; does not exist.

Look at the array that it prints out in the first statement.

there is one array with-in another array, and each array has only one index

basically all you have is this.

$newsarray[0][0] = Burli Web Server


Syntax error;

but you are trying to access this

$newsarray[0][1]  // error, index does not exist

Include the source that you are using.  Or give a link to the source.


}

Using that code ... the results are at www.kayafm.co.za/newst.php

I have no idea why the array is printed correctly - but my echoing of array
items is not

The stuff in bold SHOULD be on a new line ...

Can you take a look and offer me more advice?

S


-Original Message-
From: Jim Lucas [mailto:[EMAIL PROTECTED]
Sent: 09 February 2007 09:56 AM
To: Steven Macintyre
Subject: Re: [PHP] array within array

Steven Macintyre wrote:

Hi all,

I have an array ($articles) that contains content in this format

Textbr
More text

I am currently calling the creation of the array as such;

$articles = split(Section break, $mystring); -- this works

NOW ... I need to split each item in the articles array into its

own array

(newsarray)

I have tried

Foreach ($articles as $value) {
$newsarray = split(br, $value);
}

But this aint working ...

Can someone offer a better suggestion?

S


So, to put it all together

This 

plaintext?php

$articles[] = TextbrMore text;
$articles[] = TextbrMore textbrhi;
$articles[] = TextbrMore text;
$articles[] = TextbrMore textbrhi;
$newsarray = array();
foreach ($articles as $value) {

# use this for splitting on every single br in them
$newsarray[] = split(br, $value);
# I would recommend this instead
$newsarray[] = split(br, $value, 2);
}
var_dump($newsarray);
?

returns me this...


array(4) {
   [0]=
   array(2) {
 [0]=
 string(4) Text
 [1]=
 string(9) More text
   }
   [1]=
   array(2) {
 [0]=
 string(4) Text
 [1]=
 string(17) More textbrhi
   }
   [2]=
   array(2) {
 [0]=
 string(4) Text
 [1]=
 string(9) More text
   }
   [3]=
   array(2) {
 [0]=
 string(4) Text
 [1]=
 string(17) More textbrhi
   }
}

hope this helps






--
Enjoy,

Jim Lucas

Different eyes see different things. Different hearts beat on different 
strings. But there are times for you and me when all such things agree.


- Rush

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] array within array

2007-02-09 Thread Németh Zoltán
On p, 2007-02-09 at 09:24 +0200, Steven Macintyre wrote:
 Hi all,
 
 I have an array ($articles) that contains content in this format
 
 Textbr
 More text
 
 I am currently calling the creation of the array as such;
 
 $articles = split(Section break, $mystring); -- this works
 
 NOW ... I need to split each item in the articles array into its own array
 (newsarray)
 
 I have tried 
 
 Foreach ($articles as $value) {
   $newsarray = split(br, $value);
 }

I'm not sure what you mean by this aint working but if you want all
elements of the $articles array to be arrays created by the split()
call, then try using the following:


foreach ($articles as $key = $value) {
$newsarray = split(br, $value);
$articles[$key] = $newsarray;
}

hope that helps
Zoltán Németh

 
 But this aint working ... 
 
 Can someone offer a better suggestion?
 
 S
 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] array within array

2007-02-09 Thread Németh Zoltán
On p, 2007-02-09 at 10:10 +0100, Németh Zoltán wrote:
 On p, 2007-02-09 at 09:24 +0200, Steven Macintyre wrote:
  Hi all,
  
  I have an array ($articles) that contains content in this format
  
  Textbr
  More text
  
  I am currently calling the creation of the array as such;
  
  $articles = split(Section break, $mystring); -- this works
  
  NOW ... I need to split each item in the articles array into its own array
  (newsarray)
  
  I have tried 
  
  Foreach ($articles as $value) {
  $newsarray = split(br, $value);
  }
 
 I'm not sure what you mean by this aint working but if you want all
 elements of the $articles array to be arrays created by the split()
 call, then try using the following:
 
 
 foreach ($articles as $key = $value) {
   $newsarray = split(br, $value);
   $articles[$key] = $newsarray;

or in one line

$articles[$key] = split(br, $value);

because you don't need to waste system resources on the temporary array
$newsarray at all

greets
Zoltán Németh

 }
 
 hope that helps
 Zoltán Németh
 
  
  But this aint working ... 
  
  Can someone offer a better suggestion?
  
  S
  
 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] array within array

2007-02-08 Thread Steven Macintyre
Hi all,

I have an array ($articles) that contains content in this format

Textbr
More text

I am currently calling the creation of the array as such;

$articles = split(Section break, $mystring); -- this works

NOW ... I need to split each item in the articles array into its own array
(newsarray)

I have tried 

Foreach ($articles as $value) {
$newsarray = split(br, $value);
}

But this aint working ... 

Can someone offer a better suggestion?

S

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] array within array

2007-02-08 Thread Roman Neuhauser
# [EMAIL PROTECTED] / 2007-02-09 09:24:01 +0200:
 I am currently calling the creation of the array as such;
 
 $articles = split(Section break, $mystring); -- this works
 
 NOW ... I need to split each item in the articles array into its own array
 (newsarray)
 
 I have tried 
 
 Foreach ($articles as $value) {
   $newsarray = split(br, $value);
 }
 
 But this aint working ... 

Define this aint working.

-- 
How many Vietnam vets does it take to screw in a light bulb?
You don't know, man.  You don't KNOW.
Cause you weren't THERE. http://bash.org/?255991

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Array within array

2005-09-30 Thread Chris
Greetings PHP community,

I have a CSV text file which I need to use to update existing DB
records.

So I have the following :

$array_file = file(path/to/file);

file() creates an array comprising each line of the file, but if each
line contains 20 or so CS values, how do I go about reading each line
and updating the db.

Pseudo code :
=
$array_file = file(path/to/file);
while (explode(',',$file_array)) 
{
  do update on db for each line of array
}
=

Any pointers ?

--
Chris Blake 
Cell: 082 775 1492
Work: +27 11 880 2825
Fax : +27 11 782 0841
Mail: [EMAIL PROTECTED]

Immortality -- a fate worse than death. -- Edgar A. Shoaff

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Array within array

2005-09-30 Thread Emil Novak
?php
$array_file = file(path/to/file);
foreach($array_file as $line)
{
$e_array = explode(',',$line);
{
// do update on db for each line of array
}
}
?

Like this?

Emil Novak, Slovenia, EU

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Array within array

2005-09-30 Thread Chris Blake
On Fri, 2005-09-30 at 15:33, Emil Novak wrote:
 ?php
 $array_file = file(path/to/file);
 foreach($array_file as $line)
 {
   $e_array = explode(',',$line);
   {
   // do update on db for each line of array
   }
 }
 ?
 
 Like this?

Hi Emil,

That`s exactly how I figured it out eventuallysometimes you just
need to step away from the monitor and take a break before the answer
slaps you on the forehead... :)

Thanks

--
Chris Blake 
Cell: 082 775 1492
Work: +27 11 880 2825
Fax : +27 11 782 0841
Mail: [EMAIL PROTECTED]

If a camel flies, no one laughs if it doesn't get very far. -- Paul
White

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php