I have a string = "Name":"Susan","Age":"23","Gender":"Male";
How to store them in an array so that I can echo the value for example:
echo $array['Name']
or
echo $array['Age']
Thanks
If your string is already:
"Name":"Susan","Age":"23","Gender":"Male"
That's almost JSON, so you can just enclose it in curly brackets and convert it to turn that into an array:
$decoded = (Array)json_decode('{'.$str.'}');
json_decode() normally outputs an object, but here we're casting it to an array. This is not required, but it changes how you have to access the resulting elements.
This would render the following associative array:
array(3) {
["Name"]=>
string(5) "Susan"
["Age"]=>
string(2) "23"
["Gender"]=>
string(4) "Male"
}
Associative Arrays in PHP are what you need to achieve your task. In PHP array() are actually ordered maps i.e. associates values with a key Here is an example. An associative array is an array where each key has its own specific value. Here's an example.
$values = array("Name"=>"Susan", "Age"=>"23", "Gender"=>"Male");
echo $values['Name'];
echo $values['Age'];
echo $values['Gender'];
You can store string as json
$json = '{"Name":"Susan","Age":"23","Gender":"Male"}';
$array = json_decode($json, true);
var_dump($array);
The manual specifies the second argument of json_decode as:
assoc
When TRUE, returned objects will be converted into associative arrays.
https://stackoverflow.com/a/18576902/5546916
Try below snippet
$string = "Name":"Susan","Age":"23","Gender":"Male";
//explode string with `,` first
$s = explode(",",$string); // $s[0] = "Name":"Susan"....
$array = array();
foreach($s as $data){
$t = array();
$t = explode(":",$data); //explode with `:`
$array[$t[0]] = $t[1];
}
echo $array["name"];
Related
Is it possible to use a numeric string like "123" as a key in a PHP array, without it being converted to an integer?
$blah = array('123' => 1);
var_dump($blah);
prints
array(1) {
[123]=>
int(1)
}
I want
array(1) {
["123"]=>
int(1)
}
No; no it's not:
From the manual:
A key may be either an integer or a string. If a key is the standard representation of an integer, it will be interpreted as such (i.e. "8" will be interpreted as 8, while "08" will be interpreted as "08").
Addendum
Because of the comments below, I thought it would be fun to point out that the behaviour is similar but not identical to JavaScript object keys.
foo = { '10' : 'bar' };
foo['10']; // "bar"
foo[10]; // "bar"
foo[012]; // "bar"
foo['012']; // undefined!
Yes, it is possible by array-casting an stdClass object:
$data = new stdClass;
$data->{"12"} = 37;
$data = (array) $data;
var_dump( $data );
That gives you (up to PHP version 7.1):
array(1) {
["12"]=>
int(37)
}
(Update: My original answer showed a more complicated way by using json_decode() and json_encode() which is not necessary.)
Note the comment: It's unfortunately not possible to reference the value directly: $data['12'] will result in a notice.
Update:
From PHP 7.2 on it is also possible to use a numeric string as key to reference the value:
var_dump( $data['12'] ); // int 32
My workaround is:
$id = 55;
$array = array(
" $id" => $value
);
The space char (prepend) is a good solution because keep the int conversion:
foreach( $array as $key => $value ) {
echo $key;
}
You'll see 55 as int.
If you need to use a numeric key in a php data structure, an object will work. And objects preserve order, so you can iterate.
$obj = new stdClass();
$key = '3';
$obj->$key = 'abc';
You can typecast the key to a string but it will eventually be converted to an integer due to PHP's loose-typing. See for yourself:
$x=array((string)123=>'abc');
var_dump($x);
$x[123]='def';
var_dump($x);
From the PHP manual:
A key may be either an integer or a string . If a key is the standard
representation of an integer , it will be interpreted as such (i.e.
"8" will be interpreted as 8, while "08" will be interpreted as "08").
Floats in key are truncated to integer . The indexed and associative
array types are the same type in PHP, which can both contain integer
and string indices.
I had this problem trying to merge arrays which had both string and integer keys. It was important that the integers would also be handled as string since these were names for input fields (as in shoe sizes etc,..)
When I used $data = array_merge($data, $extra); PHP would 're-order' the keys. In an attempt doing the ordering, the integer keys (I tried with 6 - '6'- "6" even (string)"6" as keys) got renamed from 0 to n ... If you think about it, in most cases this would be the desired behaviour.
You can work around this by using $data = $data + $extra; instead.
Pretty straight forward, but I didn't think of it at first ^^.
As workaround, you can encode PHP array into json object, with JSON_FORCE_OBJECT option.
i.e., This example:
$a = array('foo','bar','baz');
echo "RESULT: ", json_encode($a, JSON_FORCE_OBJECT);
will result in:
RESULT: {"0" : "foo", "1": "bar", "2" : "baz"}
I ran into this problem on an array with both '0' and '' as keys. It meant that I couldn't check my array keys with either == or ===.
$array=array(''=>'empty', '0'=>'zero', '1'=>'one');
echo "Test 1\n";
foreach ($array as $key=>$value) {
if ($key == '') { // Error - wrongly finds '0' as well
echo "$value\n";
}
}
echo "Test 2\n";
foreach ($array as $key=>$value) {
if ($key === '0') { // Error - doesn't find '0'
echo "$value\n";
}
}
The workaround is to cast the array keys back to strings before use.
echo "Test 3\n";
foreach ($array as $key=>$value) {
if ((string)$key == '') { // Cast back to string - fixes problem
echo "$value\n";
}
}
echo "Test 4\n";
foreach ($array as $key=>$value) {
if ((string)$key === '0') { // Cast back to string - fixes problem
echo "$value\n";
}
}
Strings containing valid integers will be cast to the integer type. E.g. the key "8" will actually be stored under 8. On the other hand "08" will not be cast, as it isn't a valid decimal integer.
WRONG
I have a casting function which handles sequential to associative array casting,
$array_assoc = cast($arr,'array_assoc');
$array_sequential = cast($arr,'array_sequential');
$obj = cast($arr,'object');
$json = cast($arr,'json');
function cast($var, $type){
$orig_type = gettype($var);
if($orig_type == 'string'){
if($type == 'object'){
$temp = json_decode($var);
} else if($type == 'array'){
$temp = json_decode($var, true);
}
if(isset($temp) && json_last_error() == JSON_ERROR_NONE){
return $temp;
}
}
if(#settype($var, $type)){
return $var;
}
switch( $orig_type ) {
case 'array' :
if($type == 'array_assoc'){
$obj = new stdClass;
foreach($var as $key => $value){
$obj->{$key} = $value;
}
return (array) $obj;
} else if($type == 'array_sequential'){
return array_values($var);
} else if($type == 'json'){
return json_encode($var);
}
break;
}
return null; // or trigger_error
}
Regarding #david solution, please note that when you try to access the string values in the associative array, the numbers will not work. My guess is that they are casted to integers behind the scenes (when accessing the array) and no value is found. Accessing the values as integers won't work either. But you can use array_shift() to get the values or iterate the array.
$data = new stdClass;
$data->{"0"} = "Zero";
$data->{"1"} = "One";
$data->{"A"} = "A";
$data->{"B"} = "B";
$data = (array)$data;
var_dump($data);
/*
Note the key "0" is correctly saved as a string:
array(3) {
["0"]=>
string(4) "Zero"
["A"]=>
string(1) "A"
["B"]=>
string(1) "B"
}
*/
//Now let's access the associative array via the values
//given from var_dump() above:
var_dump($data["0"]); // NULL -> Expected string(1) "0"
var_dump($data[0]); // NULL (as expected)
var_dump($data["1"]); // NULL -> Expected string(1) "1"
var_dump($data[1]); // NULL (as expected)
var_dump($data["A"]); // string(1) "A" (as expected)
var_dump($data["B"]); // string(1) "B" (as expected)
I had this problem while trying to sort an array where I needed the sort key to be a hex sha1. When a resulting sha1 value has no letters, PHP turns the key into an integer. But I needed to sort the array on the relative order of the strings. So I needed to find a way to force the key to be a string without changing the sorting order.
Looking at the ASCII chart (https://en.wikipedia.org/wiki/ASCII) the exclamation point sorts just about the same as space and certainly lower than all numbers and letters.
So I appended an exclamation point at the end of the key string.
for(...) {
$database[$sha.'!'] = array($sha,$name,$age);
}
ksort($database);
$row = reset($database);
$topsha = $row[0];
So I've a json string and an array like so :
$json_str = '{"key1":["val11", "val12", "val13"], "key2":"val2"}';
$delete_keys = array("val12");
I want to delete the values present in delete_keys from json_str['key1']. So I did the following:
$json_arr = json_decode($json_str, true);
$key1 = $json_arr['key1'];
foreach ($delete_keys as $key) {
$index = array_search($key, $key1);
if (isset($index))
unset($key1[$index]);
unset($index);
}
$json_arr['key1'] = $key1;
$json_str = json_encode($json_arr);
print $json_str;
Now the result I expected for json_str is this
{"key1":["val11", "val13"], "key2":"val2"}
But instead I get this
{"key1":{"0":"val11", "2":"val13"}, "key2":"val2"}
It works as I expected if I delete the last key though. Can someone please tell me how to get the former as the json string instead of the latter.
You should reindex array with array_values().
If keys in the array are not sequential it is an associative array.
There is an example of this phenomenon on the PHP documentation for json_encode, labelled with "Sequential array with one key unset": http://php.net/manual/en/function.json-encode.php
Reproduced here:
$sequential = array("foo", "bar", "baz", "blong");
// ...
unset($sequential[1]);
var_dump(
$sequential,
json_encode($sequential)
);
// Outputs: string(33) "{"0":"foo","2":"baz","3":"blong"}"
In order for the keys to remain sequential, you can re-number them using array_values:
$sequential = array("foo", "bar", "baz", "blong");
// ...
unset($sequential[1]);
$sequential = array_values( $sequential );
var_dump(
$sequential,
json_encode($sequential)
);
// Outputs: string(21) "["foo","baz","blong"]"
Is it possible to use a numeric string like "123" as a key in a PHP array, without it being converted to an integer?
$blah = array('123' => 1);
var_dump($blah);
prints
array(1) {
[123]=>
int(1)
}
I want
array(1) {
["123"]=>
int(1)
}
No; no it's not:
From the manual:
A key may be either an integer or a string. If a key is the standard representation of an integer, it will be interpreted as such (i.e. "8" will be interpreted as 8, while "08" will be interpreted as "08").
Addendum
Because of the comments below, I thought it would be fun to point out that the behaviour is similar but not identical to JavaScript object keys.
foo = { '10' : 'bar' };
foo['10']; // "bar"
foo[10]; // "bar"
foo[012]; // "bar"
foo['012']; // undefined!
Yes, it is possible by array-casting an stdClass object:
$data = new stdClass;
$data->{"12"} = 37;
$data = (array) $data;
var_dump( $data );
That gives you (up to PHP version 7.1):
array(1) {
["12"]=>
int(37)
}
(Update: My original answer showed a more complicated way by using json_decode() and json_encode() which is not necessary.)
Note the comment: It's unfortunately not possible to reference the value directly: $data['12'] will result in a notice.
Update:
From PHP 7.2 on it is also possible to use a numeric string as key to reference the value:
var_dump( $data['12'] ); // int 32
My workaround is:
$id = 55;
$array = array(
" $id" => $value
);
The space char (prepend) is a good solution because keep the int conversion:
foreach( $array as $key => $value ) {
echo $key;
}
You'll see 55 as int.
If you need to use a numeric key in a php data structure, an object will work. And objects preserve order, so you can iterate.
$obj = new stdClass();
$key = '3';
$obj->$key = 'abc';
You can typecast the key to a string but it will eventually be converted to an integer due to PHP's loose-typing. See for yourself:
$x=array((string)123=>'abc');
var_dump($x);
$x[123]='def';
var_dump($x);
From the PHP manual:
A key may be either an integer or a string . If a key is the standard
representation of an integer , it will be interpreted as such (i.e.
"8" will be interpreted as 8, while "08" will be interpreted as "08").
Floats in key are truncated to integer . The indexed and associative
array types are the same type in PHP, which can both contain integer
and string indices.
I had this problem trying to merge arrays which had both string and integer keys. It was important that the integers would also be handled as string since these were names for input fields (as in shoe sizes etc,..)
When I used $data = array_merge($data, $extra); PHP would 're-order' the keys. In an attempt doing the ordering, the integer keys (I tried with 6 - '6'- "6" even (string)"6" as keys) got renamed from 0 to n ... If you think about it, in most cases this would be the desired behaviour.
You can work around this by using $data = $data + $extra; instead.
Pretty straight forward, but I didn't think of it at first ^^.
As workaround, you can encode PHP array into json object, with JSON_FORCE_OBJECT option.
i.e., This example:
$a = array('foo','bar','baz');
echo "RESULT: ", json_encode($a, JSON_FORCE_OBJECT);
will result in:
RESULT: {"0" : "foo", "1": "bar", "2" : "baz"}
I ran into this problem on an array with both '0' and '' as keys. It meant that I couldn't check my array keys with either == or ===.
$array=array(''=>'empty', '0'=>'zero', '1'=>'one');
echo "Test 1\n";
foreach ($array as $key=>$value) {
if ($key == '') { // Error - wrongly finds '0' as well
echo "$value\n";
}
}
echo "Test 2\n";
foreach ($array as $key=>$value) {
if ($key === '0') { // Error - doesn't find '0'
echo "$value\n";
}
}
The workaround is to cast the array keys back to strings before use.
echo "Test 3\n";
foreach ($array as $key=>$value) {
if ((string)$key == '') { // Cast back to string - fixes problem
echo "$value\n";
}
}
echo "Test 4\n";
foreach ($array as $key=>$value) {
if ((string)$key === '0') { // Cast back to string - fixes problem
echo "$value\n";
}
}
Strings containing valid integers will be cast to the integer type. E.g. the key "8" will actually be stored under 8. On the other hand "08" will not be cast, as it isn't a valid decimal integer.
WRONG
I have a casting function which handles sequential to associative array casting,
$array_assoc = cast($arr,'array_assoc');
$array_sequential = cast($arr,'array_sequential');
$obj = cast($arr,'object');
$json = cast($arr,'json');
function cast($var, $type){
$orig_type = gettype($var);
if($orig_type == 'string'){
if($type == 'object'){
$temp = json_decode($var);
} else if($type == 'array'){
$temp = json_decode($var, true);
}
if(isset($temp) && json_last_error() == JSON_ERROR_NONE){
return $temp;
}
}
if(#settype($var, $type)){
return $var;
}
switch( $orig_type ) {
case 'array' :
if($type == 'array_assoc'){
$obj = new stdClass;
foreach($var as $key => $value){
$obj->{$key} = $value;
}
return (array) $obj;
} else if($type == 'array_sequential'){
return array_values($var);
} else if($type == 'json'){
return json_encode($var);
}
break;
}
return null; // or trigger_error
}
Regarding #david solution, please note that when you try to access the string values in the associative array, the numbers will not work. My guess is that they are casted to integers behind the scenes (when accessing the array) and no value is found. Accessing the values as integers won't work either. But you can use array_shift() to get the values or iterate the array.
$data = new stdClass;
$data->{"0"} = "Zero";
$data->{"1"} = "One";
$data->{"A"} = "A";
$data->{"B"} = "B";
$data = (array)$data;
var_dump($data);
/*
Note the key "0" is correctly saved as a string:
array(3) {
["0"]=>
string(4) "Zero"
["A"]=>
string(1) "A"
["B"]=>
string(1) "B"
}
*/
//Now let's access the associative array via the values
//given from var_dump() above:
var_dump($data["0"]); // NULL -> Expected string(1) "0"
var_dump($data[0]); // NULL (as expected)
var_dump($data["1"]); // NULL -> Expected string(1) "1"
var_dump($data[1]); // NULL (as expected)
var_dump($data["A"]); // string(1) "A" (as expected)
var_dump($data["B"]); // string(1) "B" (as expected)
I had this problem while trying to sort an array where I needed the sort key to be a hex sha1. When a resulting sha1 value has no letters, PHP turns the key into an integer. But I needed to sort the array on the relative order of the strings. So I needed to find a way to force the key to be a string without changing the sorting order.
Looking at the ASCII chart (https://en.wikipedia.org/wiki/ASCII) the exclamation point sorts just about the same as space and certainly lower than all numbers and letters.
So I appended an exclamation point at the end of the key string.
for(...) {
$database[$sha.'!'] = array($sha,$name,$age);
}
ksort($database);
$row = reset($database);
$topsha = $row[0];
I have this variable $csv = '3,6,7,8'; that i need to convert to a square bracketed array of the form $csv_array = [3,6,7,8];
If i explode the csv like $new_array=explode(",",$csv);,it does not give me the array i want.
This is a running example http://3v4l.org/kYC0g
The code
$csv = '3,6,7,8';
$new_csv = '['.$csv.']';
if(is_array($new_csv)){
echo 'true';
}
else{
echo 'false';
//this is false
}
echo '<br/>';
$new_array=explode(",",$csv);
print_r($new_array);
//not what i am looking for
echo '<br/>';
print_r($new_csv);
echo '<br/>';
echo $new_csv;
As stated by a fellow stacker
RichardBernards - The two 'types' of array are exactly the same in PHP. If you are looking for JSON
An example of using JSON to achieve what it is you require:
To encode:
$csv = '3,6,7,8';
$array = explode(",", $csv);
$json = json_encode($array);
echo $json;
To decode $csv into the normal array you provided it:
$decoded = json_decode($json, true);
var_dump($decoded);
And then to return it to its original format:
$csv = implode(',', $decoded);
See json_encode() for more information, and also see it's opposite json_decode()
Keep in mind that JSON is literally a string and is not compatible associatively in PHP until it is decoded using the json_decode() function mentioned above. With that being said, replacing true with false in the example above would create an object array and multi-dimensional arrays would require them to be referenced differently, e.g. $array->result.
It would also be worth bringing to your attention the beauty of the predefined CSV functions within PHP
Adding [ and ] to string does not makes it PHP array.
$csv = '3,6,7,8';
var_dump(explode(',', $csv));
array(4) {
[0]=>
string(1) "3"
[1]=>
string(1) "6"
[2]=>
string(1) "7"
[3]=>
string(1) "8"
}
That is equal to ["3", "6", "7", "8"] as PHP array.
To get JSON array form it, use json_encode(explode(',', $csv)). Or simply $jsonArray = "[{$csv}]" if you need JSON array (not PHP array, because it will be simple string).
Is it possible to use a numeric string like "123" as a key in a PHP array, without it being converted to an integer?
$blah = array('123' => 1);
var_dump($blah);
prints
array(1) {
[123]=>
int(1)
}
I want
array(1) {
["123"]=>
int(1)
}
No; no it's not:
From the manual:
A key may be either an integer or a string. If a key is the standard representation of an integer, it will be interpreted as such (i.e. "8" will be interpreted as 8, while "08" will be interpreted as "08").
Addendum
Because of the comments below, I thought it would be fun to point out that the behaviour is similar but not identical to JavaScript object keys.
foo = { '10' : 'bar' };
foo['10']; // "bar"
foo[10]; // "bar"
foo[012]; // "bar"
foo['012']; // undefined!
Yes, it is possible by array-casting an stdClass object:
$data = new stdClass;
$data->{"12"} = 37;
$data = (array) $data;
var_dump( $data );
That gives you (up to PHP version 7.1):
array(1) {
["12"]=>
int(37)
}
(Update: My original answer showed a more complicated way by using json_decode() and json_encode() which is not necessary.)
Note the comment: It's unfortunately not possible to reference the value directly: $data['12'] will result in a notice.
Update:
From PHP 7.2 on it is also possible to use a numeric string as key to reference the value:
var_dump( $data['12'] ); // int 32
My workaround is:
$id = 55;
$array = array(
" $id" => $value
);
The space char (prepend) is a good solution because keep the int conversion:
foreach( $array as $key => $value ) {
echo $key;
}
You'll see 55 as int.
If you need to use a numeric key in a php data structure, an object will work. And objects preserve order, so you can iterate.
$obj = new stdClass();
$key = '3';
$obj->$key = 'abc';
You can typecast the key to a string but it will eventually be converted to an integer due to PHP's loose-typing. See for yourself:
$x=array((string)123=>'abc');
var_dump($x);
$x[123]='def';
var_dump($x);
From the PHP manual:
A key may be either an integer or a string . If a key is the standard
representation of an integer , it will be interpreted as such (i.e.
"8" will be interpreted as 8, while "08" will be interpreted as "08").
Floats in key are truncated to integer . The indexed and associative
array types are the same type in PHP, which can both contain integer
and string indices.
I had this problem trying to merge arrays which had both string and integer keys. It was important that the integers would also be handled as string since these were names for input fields (as in shoe sizes etc,..)
When I used $data = array_merge($data, $extra); PHP would 're-order' the keys. In an attempt doing the ordering, the integer keys (I tried with 6 - '6'- "6" even (string)"6" as keys) got renamed from 0 to n ... If you think about it, in most cases this would be the desired behaviour.
You can work around this by using $data = $data + $extra; instead.
Pretty straight forward, but I didn't think of it at first ^^.
As workaround, you can encode PHP array into json object, with JSON_FORCE_OBJECT option.
i.e., This example:
$a = array('foo','bar','baz');
echo "RESULT: ", json_encode($a, JSON_FORCE_OBJECT);
will result in:
RESULT: {"0" : "foo", "1": "bar", "2" : "baz"}
I ran into this problem on an array with both '0' and '' as keys. It meant that I couldn't check my array keys with either == or ===.
$array=array(''=>'empty', '0'=>'zero', '1'=>'one');
echo "Test 1\n";
foreach ($array as $key=>$value) {
if ($key == '') { // Error - wrongly finds '0' as well
echo "$value\n";
}
}
echo "Test 2\n";
foreach ($array as $key=>$value) {
if ($key === '0') { // Error - doesn't find '0'
echo "$value\n";
}
}
The workaround is to cast the array keys back to strings before use.
echo "Test 3\n";
foreach ($array as $key=>$value) {
if ((string)$key == '') { // Cast back to string - fixes problem
echo "$value\n";
}
}
echo "Test 4\n";
foreach ($array as $key=>$value) {
if ((string)$key === '0') { // Cast back to string - fixes problem
echo "$value\n";
}
}
Strings containing valid integers will be cast to the integer type. E.g. the key "8" will actually be stored under 8. On the other hand "08" will not be cast, as it isn't a valid decimal integer.
WRONG
I have a casting function which handles sequential to associative array casting,
$array_assoc = cast($arr,'array_assoc');
$array_sequential = cast($arr,'array_sequential');
$obj = cast($arr,'object');
$json = cast($arr,'json');
function cast($var, $type){
$orig_type = gettype($var);
if($orig_type == 'string'){
if($type == 'object'){
$temp = json_decode($var);
} else if($type == 'array'){
$temp = json_decode($var, true);
}
if(isset($temp) && json_last_error() == JSON_ERROR_NONE){
return $temp;
}
}
if(#settype($var, $type)){
return $var;
}
switch( $orig_type ) {
case 'array' :
if($type == 'array_assoc'){
$obj = new stdClass;
foreach($var as $key => $value){
$obj->{$key} = $value;
}
return (array) $obj;
} else if($type == 'array_sequential'){
return array_values($var);
} else if($type == 'json'){
return json_encode($var);
}
break;
}
return null; // or trigger_error
}
Regarding #david solution, please note that when you try to access the string values in the associative array, the numbers will not work. My guess is that they are casted to integers behind the scenes (when accessing the array) and no value is found. Accessing the values as integers won't work either. But you can use array_shift() to get the values or iterate the array.
$data = new stdClass;
$data->{"0"} = "Zero";
$data->{"1"} = "One";
$data->{"A"} = "A";
$data->{"B"} = "B";
$data = (array)$data;
var_dump($data);
/*
Note the key "0" is correctly saved as a string:
array(3) {
["0"]=>
string(4) "Zero"
["A"]=>
string(1) "A"
["B"]=>
string(1) "B"
}
*/
//Now let's access the associative array via the values
//given from var_dump() above:
var_dump($data["0"]); // NULL -> Expected string(1) "0"
var_dump($data[0]); // NULL (as expected)
var_dump($data["1"]); // NULL -> Expected string(1) "1"
var_dump($data[1]); // NULL (as expected)
var_dump($data["A"]); // string(1) "A" (as expected)
var_dump($data["B"]); // string(1) "B" (as expected)
I had this problem while trying to sort an array where I needed the sort key to be a hex sha1. When a resulting sha1 value has no letters, PHP turns the key into an integer. But I needed to sort the array on the relative order of the strings. So I needed to find a way to force the key to be a string without changing the sorting order.
Looking at the ASCII chart (https://en.wikipedia.org/wiki/ASCII) the exclamation point sorts just about the same as space and certainly lower than all numbers and letters.
So I appended an exclamation point at the end of the key string.
for(...) {
$database[$sha.'!'] = array($sha,$name,$age);
}
ksort($database);
$row = reset($database);
$topsha = $row[0];