-1

I have an associative array in my controller. The code is :

$patient_indoor[] = array (
 

);

$patient_indoor[] = array (
  array('id'=>$p->id,'name'=>$p->name,'mobile'=>$p->mobile,'due'=>$due),

);

When I try to print the value of the array in the blade file by the following code, It shows nothing. If I remove the @isset block, it says undefined Array key "id" . How can I fix the issue.

 @foreach($patient_indoor as $p) ?>
@isset($p['id'])
  <td>  {{$p['id']}} </td>
@endisset
@endforeach
1
  • Can you show us the entire code while forwarding the data to view? $patient_indoor Commented Jul 10, 2022 at 14:23

2 Answers 2

2
$patient_indoor[] = array (
  array('id'=>$p->id,'name'=>$p->name,'mobile'=>$p->mobile,'due'=>$due),

);

will return array as:

$patient_indoor[0][index]["id"]

Try this:

$patient_indoor = array (
  array('id'=>$p->id,'name'=>$p->name,'mobile'=>$p->mobile,'due'=>$due),

);
Sign up to request clarification or add additional context in comments.

Comments

1

You defined $patient_indoor[] an array.

Replace it with $patient_indoor and it will be ok.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.