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!

Link to comment
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.