-1

I wrote a code like this in a function:

preg_match_all('/{ali\s+([^}\s]+)\s*}/', $row->text, $matches, PREG_SET_ORDER);
$m=$matches[0][1];

When I write this:

$row->text=$m;

It returns the value (for example "name" in "{ali name}" and "id" in "{ali id}"),but when I write this:

$a->name='hasan';
$a->id='14';
$row->text=$a->$m;

It says:

Notice: Undefined offset: 0 in ... on line 2

What's the problem?! I tested existance of spaces,tabs,etc in the string but there was not any of them!

user1904238
  • 1
  • 1
  • 4

1 Answers1

2

Try with isset() checking

if(isset($matches[0][1])){
//Code here
}
웃웃웃웃웃
  • 11,829
  • 15
  • 59
  • 91