0

I have this code:

<?php
$query = mysqli_query($sqlnews,'SELECT * FROM news ORDER BY id DESC');
$count = 0;
while($count < 4 && $output = mysqli_fetch_assoc($query))
{
      $count++;
      echo '<div class="item"><div class="testimonials-box"><div class="testimonial-details"><h1><a class="news_subject" href="news.php?newsid='.$output['id'].'">'.$output['subject_en'].'</a></h1><br />';
      echo '<span class="news_author">'.$output['postedby'].'</span><b> | </b>';
      echo '<span class="news_date">'.date('l, d F Y', strtotime($output['date'])).'</span><div class="devider"></div>';
      echo '<span class="news_short">'.$output['short_description_en'].'</span></div></div>';
      echo '</div>'; 
}
?>

I wanna get the variable $output using array from another variable that also has an array, like this: $output['$id["1"]'] I get an error when trying to do this that says: Undefined index: $id["1"] in. Notice that the array from $id is from antoher php file that is included in this one.

Thanks!

1 Answer 1

1

Just remove the apostrophes around $id["1"]:

$output[$id["1"]]

Otherwise, the '$id["1"]' is treated literally as a string index.

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

2 Comments

Okay, this works! But i have the array in another file and it says me that it's not defined.
No, my fault, i had the array like "'id'", and it has to be like "id" without the ''. Thanks a lot!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.