Modifying array

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

User avatar
ruturajv
php-forum Super User
php-forum Super User
Posts: 1280
Joined: Sat Mar 22, 2003 9:42 am
Location: Mumbai, India
Contact:

Modifying array

Postby ruturajv » Fri Aug 29, 2003 10:51 pm

I have an array with strings in it
now I want to update the array with attaching single quotes to it

eg
$ar[0] = val1;
$ar[1] = val1;

change to
$ar[0] = 'val1';
$ar[1] = 'val1';

I don't remember what array function can help change the contents of the array! :?: :!:

User avatar
ruturajv
php-forum Super User
php-forum Super User
Posts: 1280
Joined: Sat Mar 22, 2003 9:42 am
Location: Mumbai, India
Contact:

found it

Postby ruturajv » Fri Aug 29, 2003 11:05 pm

found It sorry to disturb you all
if you know any other soln :idea:

Code: Select all

//function for adding quotes
   function add_quotes(&$q1, $qk)
   {
      $q1 = "'" . $q1 . "'";
      $keyword[$qk] = $q1;

   }

   if(array_walk($keyword, 'add_quotes')) {
      //echo 'succ';
   }

sigix
php-forum Active User
php-forum Active User
Posts: 364
Joined: Mon Jul 14, 2003 9:39 pm
Location: /Earth/Xion

Postby sigix » Sat Aug 30, 2003 1:18 am

both are correct ;
first one is right :arrow:

User avatar
swirlee
Moderator
Moderator
Posts: 2272
Joined: Sat Jul 05, 2003 1:18 pm
Location: A bunk in the back
Contact:

Postby swirlee » Sun Aug 31, 2003 11:12 am

sigix wrote:both are correct


What do you mean both? It's just one piece of code. You need the whole thing to do it to the whole array. Maybe you should read the documentation for array_walk().


Return to “PHP coding => General”

Who is online

Users browsing this forum: No registered users and 2 guests