Jump to content

preg_match() expects parameter 2 to be string, array given in...


snolan760

Recommended Posts

I’m trying to get one “id/number” from an array, below is my code.

 

$Groups = array("Groups");

$groups = $myApp->loadCon($cid, $Groups);

 

while(list($key, $value) = each($groups)) {

echo "<font id=\"key\"><u>List of Tags</u></font> <br> <font id=\"value\">$value</font> <br><br>";

}

 

With the image attached, I want to be able to grab the “940” id and send a user to another page depending if they have that “id” or not. I know how to redirect someone, but I can’t seem to get just the one “id” from an array. Would I need to use preg_match???

Thx,

SJ

 

 

[attachment deleted by admin]

Couldn't you just loop through the groups array?

 

foreach(explode(",", $array['groups']) as $g){
  if($g == '940'){
    // has id 940
  }
}

 

Or, if you wanted to use preg_match():

 

if(preg_match("#(940)#", $array['groups'])){
// has id 940
}

 

Hope that helps.

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.