PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
pelegk2
Forum Regular
Posts: 633 Joined: Thu Nov 27, 2003 5:02 am
Location: Israel - the best place to live in after heaven
Contact:
Post
by pelegk2 » Sun Jul 04, 2004 10:22 am
i have an array for example like this :
Array ( [r_id] => 014 [el_id] => 83 [rd_num] => 3 [order_id] => 10322 [el_id_3] => 76_3 [PHPSESSID] => bfc85ce685af64607fa723e77bcfa259 ) 1
and i want to go over the array and check all the cells
that there index start with "el_id_" to get each cell its full name for example : el_id_3 and its value 76_3
how can i do this?
thnaks in advance
peleg
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Sun Jul 04, 2004 10:28 am
regexes are probably the quickest code for it:
Code: Select all
<?php
$data = Array ( 'r_id' => 014, 'el_id' => 83, 'rd_num' => 3, 'order_id' => 10322, 'el_id_3' => '76_3', 'PHPSESSID' => 'bfc85ce685af64607fa723e77bcfa259' );
$captured = array();
foreach($data as $k => $v)
{
if(preg_match('#^el_id_.+$#i',$k))
$captured[$k] = $v;
}
?>
pelegk2
Forum Regular
Posts: 633 Joined: Thu Nov 27, 2003 5:02 am
Location: Israel - the best place to live in after heaven
Contact:
Post
by pelegk2 » Sun Jul 04, 2004 10:37 am
thnaks alot
can u just tell me why is the :
#^
for what is that?
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Sun Jul 04, 2004 10:40 am
# is the character I used to surround the regex (required for preg* functions), ^ tells it to match only from the beginning of the string.
pelegk2
Forum Regular
Posts: 633 Joined: Thu Nov 27, 2003 5:02 am
Location: Israel - the best place to live in after heaven
Contact:
Post
by pelegk2 » Sun Jul 04, 2004 10:48 am
ok thnaks alot!