Wordpress DB string to array (ok)

https://stackoverflow.com/questions/33199199/wordpress-db-string-to-array

I'm fetching a string from Wordpress DB that look's like this:

a:21:{s:18:"openhours_Sun_text";s:17:"String1";s:19:"openhours_Sun_start";s:4:"9:00";s:17:"openhours_Sun_end";s:5:"22:00"; s:18:"openhours_Mon_text";s:13:"String2";s:19:"openhours_Mon_start";s:4:"9:00";s:17:"openhours_Mon_end";s:5:"22:00"; s:18:"openhours_Tue_text";s:17:"String3";s:19:"openhours_Tue_start";s:4:"9:00";s:17:"openhours_Tue_end";s:5:"22:00"; s:18:"openhours_Wed_text";s:17:"String4";s:19:"openhours_Wed_start";s:4:"9:00";s:17:"openhours_Wed_end";s:5:"22:00"; s:18:"openhours_Thu_text";s:8:"String5";s:19:"openhours_Thu_start";s:4:"9:00";s:17:"openhours_Thu_end";s:5:"22:00"; s:18:"openhours_Fri_text";s:6:"String6";s:19:"openhours_Fri_start";s:4:"9:00";s:17:"openhours_Fri_end";s:5:"16:00"; s:18:"openhours_Sat_text";s:8:"String7";s:19:"openhours_Sat_start";s:5:"19:00";s:17:"openhours_Sat_end";s:5:"23:00";}

How i can transfer it to array in php?

<?php
			global $wpdb;
			$result = $wpdb->get_results ( "SELECT setting_data FROM wp_wpf_filters" );
			$aaa = $result[0]->setting_data;
			echo '<pre>';
				var_export($aaa);
			echo '</pre>';
		?>

You can use the maybe_unserialize function to convert the data to an array.

<?php
			global $wpdb;
			$result = $wpdb->get_results ( "SELECT setting_data FROM wp_wpf_filters" );
			$aaa = $result[0]->setting_data;
			$pia = maybe_unserialize( $aaa );
			echo '<pre>';
				var_export($pia);
			echo '</pre>';
		?>

Last updated