Welcome Guest, Not a member yet? Register   Sign In
counting items chosen in $_POST
#1

I have a form that is being returned  when a user submits. The $_POST array comes back as an array of arrays. All of the elements are available, except I have two sections that use buttons. In those sections of the array I get an array element like this:

$BC = {array} [1]
    0 = {array} [2]
        1 = "Pear Pie"
        0 = "Applefishy"

How can I get a count of how many elements appear in the sub-array? For example, in this case the answer is 2. 

In this case the answer is one:
$PR = {array} [1]
    0 = {array} [1]
        0 = "test project"

What function can I call on $PR or $BC to get that integer?
proof that an old dog can learn new tricks
Reply
#2

Hi man face same issue but solve it

Object or array in url is parae by browser

You need parse_str($url)

isset($_GET['q']) ? parse_str($request->getGet('q'), $this->q) : $this->q = [];


https://forum.codeigniter.com/thread-793...#pid387569

I tested with ci4 and angular11


Go there look propert $q(query)
Enlightenment  Is  Freedom
Reply
#3

(06-11-2021, 03:38 PM)richb201 Wrote: I have a form that is being returned  when a user submits. The $_POST array comes back as an array of arrays. All of the elements are available, except I have two sections that use buttons. In those sections of the array I get an array element like this:

$BC = {array} [1]
    0 = {array} [2]
        1 = "Pear Pie"
        0 = "Applefishy"

How can I get a count of how many elements appear in the sub-array? For example, in this case the answer is 2. 

In this case the answer is one:
$PR = {array} [1]
    0 = {array} [1]
        0 = "test project"

What function can I call on $PR or $BC to get that integer?

Can you attached a txt file of a var_dump($_POST) ?
Reply
#4

Use Count Recursive and subtract the First level count, like this:

PHP Code:
count($BCCOUNT_RECURSIVE) - count($BC);

// If your array has +3 levels, just add keys $BC[1] $BC[2] $BC[3]:

count($BC[1], COUNT_RECURSIVE) - count($BC[1]); 

PHP.net - count
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#5

(06-12-2021, 01:26 AM)InsiteFX Wrote: Use Count Recursive and subtract the First level count, like this:

PHP Code:
count($BCCOUNT_RECURSIVE) - count($BC);

// If your array has +3 levels, just add keys $BC[1] $BC[2] $BC[3]:

count($BC[1], COUNT_RECURSIVE) - count($BC[1]); 

PHP.net - count


Thanks. I will try this out. 
proof that an old dog can learn new tricks
Reply




Theme © iAndrew 2016 - Forum software by © MyBB