Login | Register | FAQ
Anonymous

Lesson 8: How to find the size of an array

+ Post a reply

4 posts Page 1 of 1


Lesson 8: How to find the size of an array

by Dolce » Fri Nov 22, 2013 3:14 am

In lesson 8, there is a suggestion of using the following code:

<?php
foreach ($arrFruits as $x){
echo $x
}
?>

I have uploaded it using the $fruitlist example, trying to merge the above code with the <ul> <li></il></ul> but the list appears that the fruit items are not align with the bullets. I wonder what is wrong with the position or other reasons that caused it. My link is as follows:

http://saowai.netne.net/arrays-loop-foreach.php
User avatar

Dolce

  • Posts: 9
  • Joined: Thu Oct 17, 2013 1:14 am

Re: Lesson 8: How to find the size of an array

by XainPro » Fri Nov 22, 2013 8:18 am

i think it's a bad example in lesson 8
you can get the size of array by using this method
Code: Select all
<?php
$fruits = array("apple","orange","mango");
echo count($fruits);
?>


And if you want to combine the foreach with ul and li you can do it like this

Code: Select all
<?php
$fruits = array("apple","orange","mango");
echo '<ul>';
      foreach ($fruits as $x) {
         echo '<li>'.$x.'</li>';
      }
echo '</ul>';

?>
User avatar

XainPro

  • Posts: 3933
  • Joined: Fri Feb 17, 2012 8:10 pm

Re: Lesson 8: How to find the size of an array

by Dolce » Sun Nov 24, 2013 11:19 pm

Very Good ! I wonder why the tutorial gave us bad examples. I tried both suggestions. The count of fruits and ul.li and ol.li, all of them work perfectly. Thanks a lot ! It makes me feel more like to learn building website because of these forums.
User avatar

Dolce

  • Posts: 9
  • Joined: Thu Oct 17, 2013 1:14 am

Re: Lesson 8: How to find the size of an array

by XainPro » Mon Nov 25, 2013 4:09 pm

Dolce Good luck for further learning
User avatar

XainPro

  • Posts: 3933
  • Joined: Fri Feb 17, 2012 8:10 pm


+ Post a reply

Page 1 of 1