Jump to content

edit array value


Destramic

Recommended Posts

hey guys i have an array but want to add "n." infront of each key value...example

n.news_id, n.user_id etc...is there a simple way/function of doing it other than changing the values through a loop?

 

Array

(

    [news] => Array

        (

            [0] => news_id

            [1] => user_id

            [2] => news

            [3] => date

            [4] => time

        )

)

 

Link to comment
https://forums.phpfreaks.com/topic/225537-edit-array-value/
Share on other sites

Hi,

 

 

try the array_walk_recursive function.

 

 

Heres an example:

 

 

$array = array('a' => 2, 'b' => array('c', 'd', 2, 3));

 

 

function modder(&$item, $key)

{

    if (is_string($item)) $item = 'n.'.$item;

}

 

 

array_walk_recursive($array, 'modder');

 

Link to comment
https://forums.phpfreaks.com/topic/225537-edit-array-value/#findComment-1164601
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.