Jump to content

Recommended Posts

Hi, how would I echo all the different values after the top level ([products]) - Basicly I need to pull all the sub levels ([product-id], [product-name], [technology-type]...etc.) from each of the [products] - there are 2 in the example below but the acual array has about 20.

 

[products] => Array
        (
            [0] => Array
                (
                    [product-id] => Array
                        (
                            [format] => counting
                            [value] => 1235
                        )

                    [product-name] => Array
                        (
                            [format] => text
                            [value] => Home 512k Classic
                        )

                    [technology-type] => Array
                        (
                            [format] => text
                            [value] => adsl
                        )

                    [capped] => Array
                        (
                            [format] => yesno
                            [value] => Y
                        )

                    [service-speed] => Array
                        (
                            [format] => counting
                            [value] => 524288
                        )

                    [contention] => Array
                        (
                            [format] => counting
                            [value] => 50
                        )

                    [care-availability] => Array
                        (
                            [format] => yesno
                            [value] => Y
                        )

                    [care-level] => Array
                        (
                            [format] => text
                            [value] => standard
                        )

                    [realms] => Array
                        (
                            [0] => Array
                                (
                                    [realm] => Array
                                        (
                                            [format] => text
                                            [value] => -flipsolutions@surfdsluk
                                        )

                                )

                        )

                )

            [1] => Array
                (
                    [product-id] => Array
                        (
                            [format] => counting
                            [value] => 1236
                        )

                    [product-name] => Array
                        (
                            [format] => text
                            [value] => Home 1mb Classic
                        )

                    [technology-type] => Array
                        (
                            [format] => text
                            [value] => adsl
                        )

                    [capped] => Array
                        (
                            [format] => yesno
                            [value] => Y
                        )

                    [service-speed] => Array
                        (
                            [format] => counting
                            [value] => 1048576
                        )

                    [contention] => Array
                        (
                            [format] => counting
                            [value] => 50
                        )

                    [care-availability] => Array
                        (
                            [format] => yesno
                            [value] => Y
                        )

                    [care-level] => Array
                        (
                            [format] => text
                            [value] => standard
                        )

                    [realms] => Array
                        (
                            [0] => Array
                                (
                                    [realm] => Array
                                        (
                                            [format] => text
                                            [value] => -flipsolutions@surfdsluk
                                        )

                                )

                        )

                )

 

I guess it would be something like this in a loop -but I cannot figure it out.

<?php
echo ['products']
?>

 

I hope I have explained myself - if not please ask.

 

Thanks for looking.

Thanks for the reply - this returns:

 

format = countingvalue = 1235format = textvalue = Home 512k Classicformat = textvalue = adslformat = yesnovalue = Yformat = countingvalue = 524288format = countingvalue = 50format = yesnovalue = Yformat = textvalue = standardformat = textvalue =

 

but I dont think this going to work anyway, the bigger picture is that I want to get each product to return into a form with a radio button before each row where the user can select which product they want to goahead with. Then when the submit button is pressed the product id is posted to the next script - but I cannot figure it out.

your array name is 'L'?

 

Look for 'L' in the script below and swap that out with the array name if 'L' isnt it.

 

for ($r=0; $r<sizeOf($L); $r++) {
    for ($c=0; $c<sizeOf($L[$r]); $c++) {
        echo $L[$c][$r];
    }
    echo '<br>';
}

 

This should output your list within a grid format.

You should take another look at Ken2K7's code.

 

Test this if you don't believe him (and me) that it does work:

<?php
function traversal ($arr)
{
	foreach ($arr as $key => $value)
	{
		if(is_array($value))
		{
			traversal($value);
		}
		else
		{
			echo $value.'<br />';
		}
	}
}
$array = array(
'this',
'does',
'work',
'honestly.'
);
traversal($array);
?>

If it doesn't, there's something horrifically wrong with your array.

Thanks for the reply - this returns:

 

format = countingvalue = 1235format = textvalue = Home 512k Classicformat = textvalue = adslformat = yesnovalue = Yformat = countingvalue = 524288format = countingvalue = 50format = yesnovalue = Yformat = textvalue = standardformat = textvalue =

 

but I dont think this going to work anyway, the bigger picture is that I want to get each product to return into a form with a radio button before each row where the user can select which product they want to goahead with. Then when the submit button is pressed the product id is posted to the next script - but I cannot figure it out.

 

the php  code they gave you works perfectly for you problem ;) some simple modifications to add that radio button and everything should work just fine ;)

What about

 

<?php
$products = array();
foreach ($L['products'] as $array) {
$products[$array['product-id']['value']] = $array['product-name']['value'];
}
foreach ($products as $id => $name) {
echo '<input type="radio" name="product" value="' . $id . '" /><span>' . $name . '</span><br />';
}
?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.