So currently I am having some issues with trying to access an element in this multidimensional array. So what I am trying to do is to create 3 different arrays of different classes, and then return them in array at the end.
The problem comes when I am trying to accsess one of the array's in the $result array. I have checked and there are elements in the array's but I am unable to access them.
public function search($searchString) : array
{
$bloggArr[] = array();
$bloggerArr[] = array();
$innleggArr[] = array();
$stmt = $this->db->prepare("SELECT * FROM blogg WHERE
bnavn=:bnavn");
$stmt->bindParam('bnavn', $searchString, PDO::PARAM_STR);
$stmt->execute();
while ($blogg=$stmt->fetchObject("Blogg"))
{
$bloggArr[]=array('blogg'=>$blogg);
echo $bloggArr['blogg']->hentBnavn();
// sort($bloggArr);
}
$stmt = $this->db->prepare("SELECT * FROM blogger WHERE
fornavn=:fornavn OR etternavn=:etternavn");
$stmt->bindParam('fornavn', $searchString, PDO::PARAM_STR);
$stmt->bindParam('etternavn', $searchString, PDO::PARAM_STR);
$stmt->execute();
while ($blogger = $stmt->fetchObject("Blogger"))
{
$bloggerArr[]= array('blogger' => $blogger);
// sort($bloggArr);
}
$stmt = $this->db->prepare("SELECT * FROM innlegg WHERE tittel=:tittel");
$stmt->bindParam('tittel', $searchString, PDO::PARAM_STR);
$stmt->execute();
while ($innlegg = $stmt->fetchObject("Innlegg"))
{
$innleggArr[] = array('innlegg' => $innlegg);
// sort($innleggArr);
}
$result = array('bloggArr' => $bloggArr, 'bloggerArr' =>
$bloggerArr, 'innleggArr' => $innleggArr);
return $result;
}
I thought I would be able to access the element in the second array by:
echo $resultat['bloggArr']['blogg']->SomeFunction();
the problem is that I get the error message that ['blogg'] is Undefined index. I am been unable to find a way to access the second array elements for a while now, and are wondering if anyone could point me in the right direction. Thanks for all help.