Jump to: navigation, search

PHP HTML Dynamic List From Array

From w3cyberlearnings

Contents

PHP Dynamic HTML List from Array

Makes Order or Un-order List from array.

Example 1: Make from a normal array

  • Un-order List
<?php

$actors = array(
	 'Greta Garbo',
	 'Andy Garcia',
	 'Ava Gardner',
	 'Lucy Johnson'
);

echo '<ul>';
foreach ($actors as $actor) {
	echo '<li>';
	echo $actor;
	echo '</li>';
}
echo '</ul>';
?>

Output: HTML Source

<ul>
<li>Greta Garbo</li>
<li>Andy Garcia</li>
<li>Ava Gardner</li>
<li>Lucy Johnson</li>
</ul>

Example 2

  • Order List
<?php

$actors = array(
	 'Greta Garbo',
	 'Andy Garcia',
	 'Ava Gardner',
	 'Lucy Johnson'
);

echo '<ol>';
foreach ($actors as $actor) {
	echo '<li>';
	echo $actor;
	echo '</li>';
}
echo '</ol>';
?>


Related Links


Dynamic HTML From Array
  1. Dynamic Drop Down List with Array
  2. Dynamic List with Array
  3. Dynamic Radio with Array
  4. Dynamic Checkbox with Array
Dynamic HTML From Database
  1. Dynamic Drop Down List with Database
  2. Dynamic List from Database
  3. Dynamic Radio from Database
  4. Dynamic Checkbox from database
Dynamic HTML with Ajax
  1. Dynamic Drop Down List with Ajax
  2. Dynamic List with Ajax
  3. Dynamic Radio with Ajax
  4. Dynamic Checkbox with Ajax
  5. Dynamic Form with Ajax
Others Related
  1. Dynamic Drop down with default option
  2. How to retrieve Form Data
Navigation
Web
SQL
MISC
References