Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Is there a way to chop an array depending on the value of a sub-array?

Status
Not open for further replies.

silkk

Programmer
Jul 14, 2008
16
0
0
CZ
Hi guys,

I have an array with subarrays and I need to cut these subarrays which have a specific value in them.
Is it possible?



Cheers,
M.
 
This array has values which hold strings and my goal is to find these values which have a specific word inside,to cut them (like cut & paste) and the array to remain with the rest of its values.
The array is presentig the text of one bank file and the structure is specific.

 
have you looked at array_filter?

Code:
$newArray = array_filter($array, 'myFilter');


function myFilter ($value){
  return ($value !== 'someothervalue');
}
 
Hi jpadie,
yep,I took a look at the array_filter thingy and I couldn't find anything usefull at this moment.
I mean - I have to search into each array value for a matching keyword and if the match is present to output the entire block.
I used the code u've posted in my previous thread:

$pattern = '/'.$word1.'(.*?)'.$word2.'/imsx';
preg_match_all($pattern,file_get_contents($file), $matches);
echo "<pre>".print_r($matches,true).'</pre>';

well,this outputs an array like:
Array
(
[0] => Array
(
[0] => first string block like
[1] => second
[2] => third

probably I'm missing something here ... I've tried almost everything.





 
well the preg_match looks ok. but from your original question in this thread the array_filter should work fine too.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top