PHP: How to Retrieve the String of an Array That Contain Only One Value
If an array in PHP has only one value, you can get that value as a string by using the following methods:
array_shift #
Using the array_shift() function: This function removes the first element from an array and returns the value. If the array has only one element, the value of that element will be returned
$array = array("only_value");
$string = array_shift($array);
echo $string;
reset #
Using the reset() function: This function resets the internal pointer of an array to the first element and returns the value of that element. If the array has only one element, the value of that element will be returned
$array = array("only_value");
$string = reset($array);
echo $string;
current #
Using the current() function: This function returns the value of the current element of an array. If the array has only one element, the value of that element will be returned
$array = array("only_value");
$string = current($array);
echo $string;
array_pop #
Using the array_pop() function: This function removes the last element from an array and returns the value. If the array has only one element, the value of that element will be returned
$array = array("only_value");
$string = array_pop($array);
echo $string;
All of these methods will work for an array with only one value and will return that value as a string. You can choose the one that best suits your needs.