'Can`t get to array variable PHP [duplicate]
I want to display only certain data from database on my page, so I end my foreach loop with if and break; statement. I checked with var_dump() and the data is being provided from database correctly, function getName() is also correct.
Moreover I inserted there a test "echo"test"; which is displaying well. But getName() is still missing.
I think that problem might be with this if statement, because when I delete it everything works correctly (except that I get data I dont want to get).
Same situation is when I insert if statement after the getName() function - this part of the code is not executed, it seems.
<?php //var_dump($leagues); ?>
<?php foreach($leagues as $leauge): ?>
<?php if($leauge->getLevel() != 'A') { break; } ?>
<li>
<i class="fas fa-long-arrow-alt-right"></i>
<?php $leauge->getName(); echo "test"; ?>
</li>
<?php endforeach; ?>
Solution 1:[1]
Rewriting it here so it will be more seeable. What helped me: In this line of code
<?php $leauge->getName(); echo "test"; ?>
When i want to display results i have to use
<?= instead of <?php . Why is that i dont really know.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Gutek |
