Jump to content

[SOLVED] Copy values from array in to new array?


n33dl3

Recommended Posts

Hi,

I have an array with the following values in it:

REC_DATE = 'abc'

REC_CREATE = 'abc'

REC_DONE = 'abc'

DATE = 'abc'

TEST = 'abc'

 

Now I would like to put all the values which are starting with REC in to another array, what would be the best way to achieve this?

Regards

Something like this?

 

<?php

$array = array("REC_DATE" => "abc", "REC_CREATE" => "abc", "REC_DONE" => "abc", "DATE" => "abc", "TEST" => "abc");

$rec = array();
foreach ($array as $key => $val)
{
if(strpos(strtolower($key), "rec_") === 0)
{
	$rec[substr($key, 4)] = $val;
	unset($array[$key]);
}
}

echo "<pre>";
print_r($array);
echo "\n\n\n";
print_r($rec);
echo "</pre>";

?>

 

 

Orio.

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.