1

Is it possible to change the highlighted word to numbers without changing it in database table?

wanted from this

$value['how']

to this

$value['0']

enter image description here

3
  • Can you post your DB query? Commented Aug 10, 2017 at 6:42
  • Direct approach - $value['0']=$value['how'] - unclear of what you are asking Commented Aug 10, 2017 at 6:43
  • How did you get those values? Please post your code so we can help. Commented Aug 10, 2017 at 6:44

2 Answers 2

3

Yes, you need to use array_values()

$array = array("how" => "how-value", "to" => "to-value");
print_r(array_values($array));

Output:

Array
(
    [0] => how-value
    [1] => to-value
)

EDIT BY OP

To get the value

foreach($array as $key => $value) {
  $someArray = array_values($value);
 print_r($someArray[0]);
}

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

8 Comments

yup this is exactly what i wanted, thank u very much!
Glad to help! :)
now im stuck at getting the "how value" using the array_values()
Stuck as in? You need to explain the problem.
How do i retrieve the "how" value using array_values. This code doesn't get "144" value (print_r(array_values($array[0])))
|
1

@Milan Chheda answer is correct but I am just briefing here so the user can get a better idea of that.

Use array_values() to get the values of an array.

$FormedArray = array_values($your_array);

now print that array print_r($FormedArray);

You will get your result like

Array
(
    [0] => 144
    [1] => 41
    [2] => USA
    [3] => 12
    [4] => 12
)

Here is a working example. https://eval.in/843720

3 Comments

so how do i output the 144?
yes i did, it work perfectly, just that i wanted to get the 144 using the array_values. because in the future, i wanted to get the value easier using count++
Yes, that's what you got in for each loop. And it's better to use array_values before you implement that array. Because In that loop you will get array values as one element not by an array and array_values takes an array as it's argument.

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.