0

I was bug squashing my script when I discovered that an array ($array) contained two arrays with no key like so:

array(19) {
  ["id"]=>
  string(3) "243"
  ["var"]=>
  string(4) "test"
}

array(10) {
  ["id"]=>
  int(243)
}

They both contain different data, i just removed most of it to show what I'm talking about. Now I will find the cause of this eventually and fix it, but what I need is a temporary fix to get the value of var from the first array. Currently when I use print_r and var_dump I do get the actual value of var but also a NULL. For that reason I can't seem to store the value of var in a variable.

Any ideas?

Here is the full array (with some sensitive data masked)

Array
(
    [id] => 243
    [ordering] => 0
    [state] => 1
    [checked_out] => 203
    [checked_out_time] => 2013-07-17 14:28:15
    [status] => new
    [order_id] => 84
    [username] => 267
    [ankleside] => left
    [engraving] => left
    [serial] => 152
    [color_padding] => left
    [color_shell] => left
    [scan] => SCAN_2013-07-17_xxxxxx_X_hotmail.com_LEFT.PNG
    [workfile] => WORK_2013-07-17_xxxxxx_X_hotmail.com_LEFT.png
    [stlfile] => 2013-07-17_xxxxxx_X_hotmail.com_LEFT_.jpg
    [timespent] =>
    [created_by] => 203
)

Array
(
    [id] => 243
    [status] => new
    [username] => 267
    [ankleside] => left
    [engraving] => left
    [scan] => SCAN_2013-07-17_xxxxxxx_X_hotmail.com_LEFT.PNG
    [workfile] =>
    [stlfile] => fb-foto.png
    [issues] =>
)
15
  • 3
    Aren't "id" and "var" the keys? Commented Jul 17, 2013 at 14:41
  • 1
    They is no such thing as "an array with no key". Every element of an array has a corresponding key. The output shown above is the result of two separate variables passed to var_dump() Commented Jul 17, 2013 at 14:42
  • 3
    please show us your PHP-code to avoid misunderstanding Commented Jul 17, 2013 at 14:45
  • 1
    Are you sure it isn't inside a loop or something making it var_dump() twice? Try adding echo "done"; after the var_dump(); Commented Jul 17, 2013 at 14:45
  • 1
    @Ortix92 I'm just passing a single variable to var_dump() - That is simply not possible. Are you sure you're not calling it in a loop? Commented Jul 17, 2013 at 14:47

1 Answer 1

3

Somehow var_dump(); is called twice. Try adding echo "done"; after var_dump($array); to verify.

You could also add debug_print_backtrace(); to help you see how it is called twice. http://www.php.net/manual/en/function.debug-print-backtrace.php

Sign up to request clarification or add additional context in comments.

3 Comments

At this point, it's probably just hidden somewhere in a (likely sizeable) chunk of code. Seems like it's just a matter of hunting it down, not really what SO is for...
@steven there is no point. It's 200 lines of code which I'm sure you don't want to sift through. And on top of that, the method returns to a parent method which is another 600 lines of code. There are no loops in my method. So it must be in the parent
@Ortix92 see updated answer, try debug_print_backtrace(); might help you figure it out.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.