このThis code is an error and cannot be used.
I'm not sure, but isn't there an array of php defined and used as below?
I don't think it's a multidimensional array or an associative array.
[Definition Method]
$data[]=array(
'code1' = > mb_convert_encoding ($tmp_code1, "UTF-8", "SJIS"),
'code2' = > mb_convert_encoding ($tmp_code2, "UTF-8", "SJIS"),
'code3' = > mb_convert_encoding ($tmp_code3, "UTF-8", "SJIS")
);
[var_dump result]
array(3)
{
[0]=>array(4){["code1"]=>string(4)"1234"["code2"]=>string(4)"1234"["code3"]=>string(4)"1234"}
[1]=>array(4){["code1"]=>string(4)"1234"["code2"]=>string(4)"1234"["code3"]=>string(4)"1234"}
[2]=>array(4){["code1"]=>string(4)"1234"["code2"]=>string(4)"1234"["code3"]=>string(4)"1234"}
}
[Output] ← This is the problem
echo$data[0]->code1;// I could have called you like this, but it's an error...
It was like this...
Please tell me the correct definition, how to call, and the name of the array.
Also, it seems to have been stored, but I don't think the output is working.
As I commented, there are many unclear points in your question, but for now, I will answer your question first with the aim of eliminating errors such as "←This is the problem" and "Error."
PHP has only associative arrays.The Arrow operator (->
) provides access to the elements inside, called the object, which is completely different from the array.
You can create an instance of an object by defining the class
yourself and using the new
operator, as described in the linked article above, or by using an array to cast, as described in "Convert to Object" at the bottom of the page.
code:
<?php
$tmp_code1 = 'abc';
$tmp_code2 = 'def';
$tmp_code3 = 'ghi';
$data[]=(object)array(
'code1' = > mb_convert_encoding ($tmp_code1, "UTF-8", "SJIS"),
'code2' = > mb_convert_encoding ($tmp_code2, "UTF-8", "SJIS"),
'code3' = > mb_convert_encoding ($tmp_code3, "UTF-8", "SJIS")
);
echo$data[0]->code1;
echo "\n";
var_dump($data);
Output:
abc
array(1){
[0]=>
object(stdClass)#1(3){
"code1" = >
US>//#string(3) "abc"
"code2" = >
US>//#string(3) "def"
"code3" = >
US>//#string(3) "ghi"
}
}
Each property in the object can be accessed by the Arrow operator as described by yourself, so you don't know what the "how to call" you're asking is trying to say or what you're expecting to do when you say "it looks like it's stored, but it doesn't output."
The official page of PHP language has a lot of Japanese information as shown in the link above, so you should first read the link carefully, use the correct terms in the link page, and add the details to your question.
© 2024 OneMinuteCode. All rights reserved.