0

I am writing the result of a database query to an array row by row, then I am adding my own row to the last index of the array. I am using Google developer tools to view the result of the array which are as follows:

10: {strat_id:1, x_id:1, outcome_id:52, date:1364655600, status:0, rank:1,…}
>
strat_id: "1"
status: "0"
date: "1364655600"
x_id: "1"
outcome_id: "52"
rank: "1"

11: {strat_id:4, x_id:1, outcome_id:49, date:1365674916, status:1, rank:1,…}
>
strat_id: 4
status: "1"
date: 1365674916
x_id: 1
outcome_id: 49
rank: 1

The ">" character denotes where I have expanded the index. Index 10 is the last row from the database and as you can see when expanded the values are surround by quotations. Index 11 is data which I have added manually, when expanded as you can see the values are not surrounded by quotations (except for 'status').

In the interests of consistency should I bother with this detail? In order to add to the array I am using:

$newarray=array("strat_id"=>$_POST['gridID']+1, "x_id"=>$_SESSION['xID'], "outcome_id"=>$_POST['cellID']+1, "date"=>time(), "status"=>$_POST['type'], "rank"=>1);

The results of the data base I am getting with:

$result->fetch_array(MYSQLI_ASSOC)

Thanks.

3
  • 2
    Do you have any question you would like to ask us? Commented Apr 11, 2013 at 10:46
  • The quotes are to mark the value as being a string. Without the quotes the value would have been interpreted as numeric (int, long, float, etc) Commented Apr 11, 2013 at 10:49
  • Do you want them to be numbers or strings? Commented Apr 11, 2013 at 10:53

1 Answer 1

1

In the interests of consistency should I bother with this detail?

That depends on how you're going to use them. If all you need is display, that's fine; But if you need to do some comparison/calculation (considering you have date value), it would be better to convert them to number.

You may try

$record[]=array_map("intval",$result->fetch_array(MYSQLI_ASSOC));

To make every column as integer, and also later

$record[]=array("strat_id"=>intval($_POST['gridID'])+1,
    "x_id"=>$_SESSION['xID'],
    "outcome_id"=>intval($_POST['cellID'])+1,
    "date"=>time(),
    "status"=>intval($_POST['type']),
    "rank"=>1);

So to have a multidimensional array that has every element as integer.

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

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.