Walker33 Posted May 20, 2009 Share Posted May 20, 2009 I have a row with values R01,R02,R03,S01,S02,S03,A01,A02,A03. I can get them, split them, and pick out a specific value. But I need to use a wildcard to pick out all the "S" group, for example. <?php $query6 = pg_query("SELECT sublicenses FROM sublicenses WHERE license = '3RF6EWOT2'"); $getarray = pg_fetch_assoc($query6); $license6 = $getarray['sublicenses']; echo "$license6 <br><br>"; $string="$license6"; $string2=split(",",$string); print_r ($string2); // Here's where I need to remove the elements who's values contain R or A, but % and * aren't working in whatever form I use. Can remove R01, R02, A01, etc., if I predetermine that, as below. $arr = array_diff($string2, array("R01", "R01", "A01")); print_r($arr); //but can't get rid of all R's and A's ?> Always appreciate any help offered. Thanks! Link to comment https://forums.phpfreaks.com/topic/158991-using-wildcard-for-individual-array-value/ Share on other sites More sharing options...
Masna Posted May 20, 2009 Share Posted May 20, 2009 foreach($array_with_Rs_Ss_and_As as $key=>$value){ if(substr($value, 0, 1) != "S") unset($array_with_Rs_Ss_and_As[$key]); } Apply the above where you'd like to remove elements that do not start with "S." Link to comment https://forums.phpfreaks.com/topic/158991-using-wildcard-for-individual-array-value/#findComment-838495 Share on other sites More sharing options...
Walker33 Posted May 20, 2009 Author Share Posted May 20, 2009 Okay, that's getting me there, but I guess I'm not fully understanding something. I used <?php foreach($string2 as $key=>$value){ if(substr($value, 0, 1) != "S") unset($string2[$key]); echo $key; ?> and my echo pumps out the numerical count of the entire array, along with the S values. How do I isolate the S values in an echo? Link to comment https://forums.phpfreaks.com/topic/158991-using-wildcard-for-individual-array-value/#findComment-838506 Share on other sites More sharing options...
Masna Posted May 20, 2009 Share Posted May 20, 2009 <?php foreach($string2 as $key=>$value){ if(substr($value, 0, 1) != "S") unset($string2[$key]); } for($i = 0; $i < count($string2); $i++){ echo "S"; } ?> Link to comment https://forums.phpfreaks.com/topic/158991-using-wildcard-for-individual-array-value/#findComment-838509 Share on other sites More sharing options...
Walker33 Posted May 20, 2009 Author Share Posted May 20, 2009 Cool! Thanks. I think I need to read up on it to understand more, but yes, that's getting me where I want to be. Thanks! Link to comment https://forums.phpfreaks.com/topic/158991-using-wildcard-for-individual-array-value/#findComment-838511 Share on other sites More sharing options...
Masna Posted May 20, 2009 Share Posted May 20, 2009 Cool! Thanks. I think I need to read up on it to understand more, but yes, that's getting me where I want to be. Thanks! You're going to chuckle when you understand what I did. Link to comment https://forums.phpfreaks.com/topic/158991-using-wildcard-for-individual-array-value/#findComment-838514 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.