Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I think this is a tough one! Experts only?

Ok, I have some variables (returned from get_defined_vars):

Array
    (
        [lead] => Array
            (
                [2] => fstory
                [4] => him
                [5] => trtr
                [1] => 508b38ee02f502.23680245.png
            )

        [form] => Array
            (
                [id] => 3

                    )

                [fields] => Array
                    (
                        [0] => Array
                            (
                                [adminLabel] => formname
                                [id] => 2

                            )

                       [1] => Array
                        (
                            [adminLabel] => hisher
                            [id] => 4

                        [2] => Array
                            (
                                [adminLabel] => fname
                                [id] => 5

                            )

                        [3] => Array
                            (
                                [adminLabel] => sign
                                [id] => 1

                            )

                    )

I need to get the array fields key to be the [fields] [adminLabel] and the value to be the [lead] [#].

So in this example the array would have key=value

formname = fstory
fname = trtr
hisher = his
sign = 508b38ee02f502.23680245.png

Make any sense? Possible?

share|improve this question
I think new array would then look like Array ( [formname] => fstory [hisher] => him [fname] => trtr [sign] => 508b38ee02f502.23680245.png ) – Chris Oct 27 '12 at 1:59
Why the negative. I have been working on this for hours and cannot get it working. I think others would like to know how to achieve this as well if possible. – Chris Oct 27 '12 at 2:02
You are getting downvoted because didn't show any effort in your question. What did you try? What went wrong with what you tried? We are here to teach, not to program as a service. – Mark Reed Oct 27 '12 at 2:20
Ok, I am new here and just learning. – Chris Oct 27 '12 at 3:05

1 Answer

up vote 0 down vote accepted

Try this. It is untested.

$result_values  = $array['lead'];
$results        = array();
foreach ($array['form']['fields'] as $value) {
  if (is_array($value)) {
    $results[$value['adminLabel']] = $result_values[$value['id']];
  }  
}
print_r($results);
share|improve this answer
shows an empty array. – Chris Oct 27 '12 at 2:15
you did assign to $array, right ? – air4x Oct 27 '12 at 2:16
You first need to do $array = get_defined_vars();, or whatever you used to get the value in your post. – Mark Reed Oct 27 '12 at 2:19
I entered your code exactly. – Chris Oct 27 '12 at 2:19
There is no magic, Chris. The code refers to the variable $array and is not going to do a whole lot if that array doesn't have a value. – Mark Reed Oct 27 '12 at 2:19
show 3 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.