Welcome Guest, Not a member yet? Register   Sign In
Using POST, how to get array values?
#1

[eluser]suba[/eluser]
Hi,
$this->input->post('name');
this is ok

But i want to get array name value.
<input type=text name=name[]>

how to get array value?
#2

[eluser]Twisted1919[/eluser]
Code:
$post = $this->input->post('name');
echo $post[0];
Smile
#3

[eluser]skunkbad[/eluser]
Since you are actually looking for the $_POST array keys, your only real option here is to use the native $_POST array. CodeIgniter does not allow for array functions to work directly on $this->input->post().

Code:
<?php
if(isset($_POST))
{
     echo '<h1>The Post Array</h1>
           <ul>';
     foreach ($_POST as $key => $value)
     {
          echo '<li>' . $key . ' has the value of ' . $value . '</li>';
     }
     echo '</ul>';
}

but, if you would like to extend the Input class, you could use something like this function in a My_Input.php

Code:
function _fetch_from_array(&$array, $index = '', $xss_clean = FALSE)
{
    if ( $index == '' )
    {
        $new_array = FALSE;
        foreach ($array as $key => $value )
        {
            $new_array[$key] = $value;
        }
        if ($xss_clean === TRUE)
        {
            return $this->xss_clean($new_array);
        }
        else
        {
            return $new_array;
        }
    }
    
    if ( ! isset($array[$index]))
    {
        return FALSE;
    }

    if ($xss_clean === TRUE)
    {
        return $this->xss_clean($array[$index]);
    }

    return $array[$index];
}
#4

[eluser]Akinyele Olubodun[/eluser]
Like twisted1919 wrote, this might be helpful:

$item_no = $this->input->post('item_no');


for($i = 0; $i < count($item_no); $i++)
{
if( isset($item_no[$i])
echo $item_no[$i];
}




Theme © iAndrew 2016 - Forum software by © MyBB