note 72087 added to function.explode

From: Date: Tue, 02 Jan 2007 09:41:34 +0000
Subject: note 72087 added to function.explode
Groups: php.notes 
Request: Send a blank email to php-notes+get-121183@lists.php.net to get a copy of this message
I just need to create an array with array key is same as value. By explode we can get an array from key [0] to [n]. First I created an array() using explode, then assign keys using foreach and array_shift(). <?php $clist = "COLOMBO KANDY GALLE PANADURA"; $clist = explode("\n",$clist); print_r($clist); foreach ($clist as $k => $v) { $clist[$v] = array_shift($clist); } print_r($clist); ?> /////////////////// Output /////////////////////// Array ( [0] => COLOMBO [1] => KANDY [2] => GALLE [3] => PANADURA ) Array ( [COLOMBO ] => COLOMBO [KANDY ] => KANDY [GALLE ] => GALLE [PANADURA] => PANADURA ) Note : I have used explode("\n",$str) insted of explode('\n',$str). I faced problems using explode('\n',$str) for new-line. ---- Server IP: 203.199.124.111 Probable Submitter: 124.43.219.163 ---- Manual Page -- http://www.php.net/manual/en/function.explode.php Edit -- https://master.php.net/note/edit/72087 Del: integrated -- https://master.php.net/note/delete/72087/integrated Del: useless -- https://master.php.net/note/delete/72087/useless Del: bad code -- https://master.php.net/note/delete/72087/bad+code Del: spam -- https://master.php.net/note/delete/72087/spam Del: non-english -- https://master.php.net/note/delete/72087/non-english Del: in docs -- https://master.php.net/note/delete/72087/in+docs Del: other reasons-- https://master.php.net/note/delete/72087 Reject -- https://master.php.net/note/reject/72087 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#121183) next »