All Questions
65 questions
0
votes
1
answer
49
views
Why does casting the value to a string change the behavior of the code in rewriting array values?
I'm encountering an issue while attempting to update values within an array. Specifically, this portion of my code seems problematic:
$response["rates"][$key[$i]] = (string) round($response[&...
0
votes
2
answers
506
views
Why can an object be cast to an array, but cannot be passed as an array argument in PHP?
If i have an array represented in an ArrayObject like this:
$arrObj = new ArrayObject([
'foo' => 1,
'bar' => 2,
]);
Then I can comfortably cast it:
print_r((array)$array);
// output is ...
0
votes
0
answers
23
views
Convert PHP array key from integer to string value [duplicate]
I have the following array:
array (size=5)
50 => string 'Automative Repair' (length=17)
44 => string 'Baker' (length=5)
47 => string 'Barber' (length=6)
51 => string 'Bicycle ...
0
votes
0
answers
22
views
How to convert PHP string in form of array to an actual array [duplicate]
I have a PHP string which holds following:
array(
'329' => array(
'primary' => 'CIVICRM_QFID_394_', //hide this
'additional' => 'CIVICRM_QFID_398_', //hide this
'...
0
votes
1
answer
103
views
Why is the array index is undefined undefined?
I'm having trouble finding out why is the following code not working.
I've a JSON answer from a remote server, containting the following data:
...., "UserId":{"50423":"Free Kkludkjta","54379":"...
0
votes
1
answer
49
views
Does PHP not allow typecasting an array as object during initialisation of a variable?
I'm using this code to initialize a multi-dimensional array:
protected $availableAuthMechanisms = [
'open' => (object)[
'owner' => 'Mohsin.Auth',
'name' => '...
0
votes
1
answer
39
views
PHP How to owerwrite object cast to array like: (array) $object with custom function
I need something like this:
class MyClass {
$a = 'A';
$b = 'B';
public function __to_array(){
$r = (array) $this;
$r['ab'] = 'AB';
return $r;
}
};
$x = new ...
2
votes
2
answers
127
views
php type cast and array reference
I am facing a problem in PHP OOPS code.
My code is:
class Settings
{
private $client_addr = array(
'ClientID' => array('maxlength'=>'10','IsNull'=>'n'),
...
0
votes
2
answers
80
views
How to make object from array in PHP [duplicate]
How to assign array elements as object properties in PHP
$arr_zone_area = [];
foreach ($area as $key_area=>$row_area)
{
foreach ($nominalRoll as $key => $value)
{
if ($row_area-&...
2
votes
1
answer
58
views
How the numerical key of an array preceding with '+' sign is casted into integer type?
According to the PHP Manual
The key can either be an integer or a string. The value can be of any
type.
Additionally the following key casts will occur:
Strings containing valid ...
0
votes
1
answer
62
views
Cant select a array value using the key which has *_ on its key name
Im using a API which returns a object which I then turn into an array to using in my API. But I cant seem to select the values using the keys which have *_ on their name. Im not sure why. Here is a ...
0
votes
1
answer
46
views
I want to pass a string to an obect
I am using a widget which uses class objects as follows:
$p->data = array(array(array('01-Jan-2017',200),array('02-Feb-2017',210)));
but I want to build this array dynamically using data from a ...
0
votes
1
answer
224
views
Fetch Casted Value from a select query into an array
I used cast in order to convert a datatype of one of the columns in my select query.
SELECT cast(user_id as varchar(255)) from cabinet
I need to fetch the result of this value into an array but it ...
0
votes
0
answers
58
views
Array loop - Converting everything to string
OK so i am simply trying to create an array using a loop but keep the type. For some reason, when i use $array[] = .. it is casting everyting to a string. My code looks like:
foreach ($value as $val){...
2
votes
5
answers
3k
views
Flatten 2d array and cast all string values to int
How should I make this array value that is in string form
Array
(
[0] => ["1","2"]
[1] => ["5"]
)
into int form
Array
(
[0] => 1
[1] => 2
[2] => 5
)
Is it ...