Reply to Re: inserting elements within an array

Your name:

Reply:


Posted by Toby A Inkster on 04/20/07 10:18

Hendri Kurniawan wrote:

> $my_arr = explode(',', implode(',|,', $my_arr));

This will work given the example array, but won't in the general case.
Take for example, the following input:

$sinatra_songs = array(
"My Way",
"New York, New York",
"Strangers in the Night",
"Ol' Man River",
"Something Stupid",
"Bad, Bad Leroy Brown",
"That's Life"
);

You could work around that by choosing something other than a comma --
something virtually guaranteed to be unique -- as a divider.

$u = md5(microtime().rand(1,1000));
$my_arr = explode($u, implode("$u|$u", $my_arr));

--
Toby A Inkster BSc (Hons) ARCS
http://tobyinkster.co.uk/
Geek of ~ HTML/SQL/Perl/PHP/Python*/Apache/Linux

* = I'm getting there!

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация