Jump to content

using wildcard for individual array value


Walker33

Recommended Posts

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!

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?

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.