pods_cast

Cast a value as a specific type.

Description

pods_cast( (mixed) $value, (null) $cast_from = null ); 

Parameters (2)

0. $value (mixed)
The value.
1. $cast_from — Optional. (null) => null
The cast from.

Usage

  1. if ( !function_exists( 'pods_cast' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'pods-custom-content-types-and-fields/includes/data.php'; 
  3.  
  4. // The value. 
  5. $value = null; 
  6.  
  7. // The cast from. 
  8. $cast_from = null; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = pods_cast($value, $cast_from); 
  12.  

Defined (1)

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

/includes/data.php  
  1. function pods_cast( $value, $cast_from = null ) { 
  2.  
  3. if ( null !== $cast_from ) { 
  4. if ( is_object( $value ) && is_array( $cast_from ) ) { 
  5. $value = get_object_vars( $value ); 
  6. elseif ( is_array( $value ) && is_object( $cast_from ) ) { 
  7. $value = (object) $value; 
  8. else { 
  9. settype( $value, gettype( $cast_from ) ); 
  10.  
  11. return $value; 
  12.