0

I'm having a total brain freeze trying to get an array passed back from a function so that I can then access its values. The function is as follows:

function queryKeys($value) {

    global $wpdb;

    $query = "SELECT * FROM um_taxkeys WHERE key_id = 1334";
    $key = $wpdb->get_row( $query );

    $array["value_en"] = $key->name_en;
    $array["value_es"] = $key->name_es;
    $array["value_de"] = $key->name_de;


    return $array;
    //var_dump($array);

}

...and I've tried accessing it using:

...
queryKeys($value);
echo $array['value_es'];
...

...but I am getting confused on the correct syntax to use to get values back from the returned array. Appreciate some guidance please. Many thanks.

1
  • What does the function queryKeys do? It's not a valid PHP core function. Commented Nov 5, 2017 at 21:03

2 Answers 2

3

You miss return value assignment:

$array = queryKeys($values);
echo $array['value_es'];
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, now I understand where I was going wrong. You need to set the array for the returned $value that comes back first. Thanks!
0

this should work:

<?php
$array = queryKeys($value);
echo $array['value_es'];

Comments

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.