React element mapping equivalent on CodeIgniter

So let say I have this html element:

<div>
  <p>{name}</p>
  <p>{number}</p>
</div>

And also this array of object:

var obj = 
[
  {
    "name": "Luke",
    "number": "101",
  },
  {
    "name": "Mike",
    "number": "102",
  }
]

I want to map the array value and put it on html element. In react I usually do it like this:

<div>
  {obj.map((value)=>{
      return(){
        <>
          <p>{value.name}</p>
          <p>{value.number}</p>
          </br>
        </>
      }
    }
 )}
</div>

The result will be:

Luke101

Mike102

Now I want to do it on CodeIgniter but I couldn’t find the equivalent way. Maybe someone can help me to solve this or give reference. Thanks!

Answer

You can do it like this:

<?php foreach($obj as $name => $number){ ?>
   <p><?php echo $name ?></p>
   <p><?php echo $number ?></p>
<?php } ?>
  

Leave a Reply

Your email address will not be published. Required fields are marked *