We have built a database handling system with Wordpress.
Receive a list of tables from the database at the following sources:
var_dump ($a_course);
According to
array (1) {["Tables_in_hogehoge-hogehoge"] =>string (14)"consumercourse"}
And apparently it was an array, so to retrieve it from the array
array_column ($a_course,'Tables_in_hogehoge-hogehoge');and T
tried to pull from ables_in_hogehoge-hogehoge
It seems that Array () is displayed and it has not been extracted.
It would be helpful to tell me how I can extract it.
try {
$pdo = new PDO ("mysql: dbname = $db_datebase_6;host = $db_address_3;charset = utf8", $db_user, $db_password);
$stmt = $pdo->query ('SHOW TABLES');
print ('<table border = "1">');
while ($a_course = $stmt->fetch (PDO :: FETCH_ASSOC)) {
print ('<tr>');
print ('<td>');
var_dump ($a_course);
print '<br>';
$courseid = array_column ($a_course, 'Tables_in_hogehoge-hogehoge');
print_r ($courseid);
print ('</td>');
print ('<td>');
echo 'Edit course';
print ('</td>');
print ('<td>');
echo 'Clear course';
print ('</td>');
print ('</tr>');
echo '<br>';
}
print ('</table>');
} catch (PDOException $e) {
var_dump ($e);
echo 'An error has occurred. ';
}
I referred to ⇓ around print_r.
http://php.net/manual/en/function.array-column.php
I'm sure you don't understand/understood it fundamentally, but please forgive me.
ReminderI used array_column to extract from an array, but is it different?
-
Answer # 1
-
Answer # 2
The array of the argument is described as a multidimensional array (array of arrays) in the array_column manual, but the array passed to the argument is 1 Can't get it because of the array of dimensions!
http://php.net/manual/en/function.array-column.phpMultidimensional array (or array of objects) from which you want to retrieve values.
$a_course = ["Tables_in_hogehoge-hogehoge" =>"consumercourse"]; $id = array_column ($a_course, "Tables_in_hogehoge-hogehoge"); var_dump ($id); / * array (0) { } */
If there is an array in the array as shown below, you can get it with array_column.
$a_course = [ [ "Tables_in_hogehoge-hogehoge" =>"consumercourse1" ], [ "Tables_in_hogehoge-hogehoge" =>"consumercourse2" ], ]; var_dump ($a_course2); / * array (2) { [0] => array (1) { ["Tables_in_hogehoge-hogehoge"] => string (15) "consumercourse1" } [1] => array (1) { ["Tables_in_hogehoge-hogehoge"] => string (15) "consumercourse2" } } * / $ids = array_column ($a_course2, "Tables_in_hogehoge-hogehoge"); var_dump ($ids); / * array (2) { [0] => string (15) "consumercourse1" [1] => string (15) "consumercourse2" } */
As you may know, if you have a one-dimensional array, you can get it by specifying the key.
var_dump ($a_course ["Tables_in_hogehoge-hogehoge"]); / * string (14) "consumercourse" */
Related articles
- php - extract the ○ th element from the end of the two-dimensional array
- i want to know how to extract words from a sentence and make them into an array in php
- javascript php array
- reorganization of php associative array
- php - i want to update multiple tables efficiently with short code with updateall
- php - i want to get data via multiple tables in laravel
- how to bind array values in cakephp4
- php - i want to extract the laravel zip file to the specified path
- in python, i want to extract an array from a number reference
- php - unable to expand when passing an array to view with request
- php - i want to loop a multidimensional array and display it on a table
- php - make a table using an array of numbers only
- php - i want to check the array and put its value in the database if there are no duplicates
- unity php json array
- read a text file as an array with php, break each line and display it on the browser (loop processing)
- php - i want to expand and display a nested array in view
- php - i want to create an array by extracting a multidimensional array with regular expressions
- php - i want to add selected in laravel associative array
- xcode - how to randomly extract from an array and combine them into another array
- i want to extract the shortest match among all the character strings including line breaks in the regular expression of php
- php - how to exclude apostrophes with $wpdb-> prepare ()
- php - about pg4wp which runs wordpress with postures
- php - is there any reason why the user_login column is not unique for the table design provided by wordpress?
- php - does disappear when i post to wordpress with xmlrpc?
- php - how to play a video, spread the video to the entire screen width, and display text according to scrolling
- php - i want to display the number of posts in the grandchild category in wordpress
- php - i don't know how to display an existing database in vue with laravel + mysql + vuejs
- php - the a tag does not move according to the specified width wordpress
- php - wordpress management bar is not displayed
- php - wordpress i can't display the sitemap with my own theme