John Davidson

javascript - React element mapping equivalent on CodeIgniter

0 comments
Message:


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!



My Answer:
In CodeIgniter, you can achieve similar functionality by using PHP to loop through the array and generate the HTML elements. Here's an example of how you can do it:

php










This code will output the same result as the React code you provided. It loops through the `$obj` array and generates the `

` elements with the name and number values for each object in the array.

You can place this code in your CodeIgniter view file to display the data in the desired format.

Rate this post

4 of 5 based on 4481 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us