acf_force_type_array

The Advanced Custom Fields acf force type array function.

Description

acf_force_type_array( $var ); 

This function will force a variable to become an array

Parameters (1)

0. $var
The var.

Usage

  1. if ( !function_exists( 'acf_force_type_array' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'advanced-custom-fields/core/api.php'; 
  3.  
  4. // The var. 
  5. $var = null; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = acf_force_type_array($var); 
  9.  

Defined (1)

The function is defined in the following location(s).

/core/api.php  
  1. function acf_force_type_array( $var ) { 
  2.  
  3. // is array? 
  4. if( is_array($var) ) { 
  5.  
  6. return $var; 
  7.  
  8.  
  9.  
  10. // bail early if empty 
  11. if( empty($var) && !is_numeric($var) ) { 
  12.  
  13. return array(); 
  14.  
  15.  
  16.  
  17. // string  
  18. if( is_string($var) ) { 
  19.  
  20. return explode(', ', $var); 
  21.  
  22.  
  23.  
  24. // place in array 
  25. return array( $var ); 
  26. }