开发者

how to extract data from an array in PHP

开发者 https://www.devze.com 2023-02-17 15:18 出处:网络
Hello Stack Overflow i hope you are well today; So i am using jQuer开发者_如何转开发y to append a form with more input fields;

Hello Stack Overflow i hope you are well today;

So i am using jQuer开发者_如何转开发y to append a form with more input fields; The Session is storing the data as an Array for the key: Children.

I would like to know show the user the data in that array how would this be done?

jQuery that adds the input fields (some pages previous)

 $('.children-main-add').click(function(){
    var attrName = $(this).attr('name');
    var count = $(this).attr('count');
    $(this).attr('count', (parseInt(count)+1))
    var input = $('<input />');
    input.attr('type','text')
    input.attr('name',attrName+"["+count+"]" ) 
    $('.children-main').append($('<li />').append(input));
    $('#content li').removeClass('alt');
    $('#content li:odd').addClass('alt');
    $(this).val('Add Another Child');
})

The data from the session : Key: children / Value: Array

If i was not clear on something please let me know !

I thank you in advance for your help


if you want to show them as an continue string

use impode(',' , $_SESSION['children']);

Or

if(isset($_SESSION['children']) && is_array($_SESSION['children']))
{
    foreach($_SESSION['children'] as $child)
    {
      echo $child."<br />";  
      // some other html
    }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消