当前位置: 首页>>代码示例>>PHP>>正文


PHP is_assoc函数代码示例

本文整理汇总了PHP中is_assoc函数的典型用法代码示例。如果您正苦于以下问题:PHP is_assoc函数的具体用法?PHP is_assoc怎么用?PHP is_assoc使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了is_assoc函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: query

 /**
  * Creates and executes a prepared statement.
  *
  * The purpose of prepared statements is to execute a single query multiple times quickly using different variables.
  * However, we are using them here for security purposes, aware of the fact that preparing and executing single statements
  * one at a time goes against the intention of prepared statements. See "Escaping and SQL Injection" at
  * http://php.net/manual/en/mysqli.quickstart.prepared-statements.php
  *
  * For insert and update queries, passing an associative array of column names and values along with the first few
  * words of the query, up to and including the table name, is sufficient.
  *
  * Example:
  *	$my_table_values = array(
  *		'Person' => 'Bob Jones',
  *		'Company => 'BJ Manufacturing'
  *	);
  *	$query_fragment	= "INSERT INTO `my_table`";
  *	database->query( $query_fragment, $my_table_values );
  *
  * @param string [$query] Either a valid SQL query or the start of one accompanied by an associative array
  * @param array [$params] Optional. Either a list of values that will be bound to the prepared statement or an associative
  * array whose keys match the table's column names.
  * @return mixed [$result or $success] The result of a SQL SELECT, else boolean.
  */
 public function query($query, $params = null)
 {
     if (mysqli_connect_error()) {
         throw new Exception('Failed to connect(' . mysqli_connect_errno() . '): ' . mysqli_connect_error());
     }
     //var_dump( 'before: ', $query, $params );
     if (empty($params)) {
         $statement = $this->prepare($query);
         return $this->execute($statement);
     } else {
         if (!is_array($params)) {
             $params = array($params);
             // convert to array because $this->bind_params requires it
         } else {
             if (is_assoc($params)) {
                 // @todo finish reduce_params( $table_name, $params );
                 // stick $params keys into $query
                 $query = $this->build_query_from_associative_array($query, array_keys($params));
                 // Because we've just filled in the keys (column names), we only need to pass the values
                 $params = array_values($params);
             }
         }
         //var_dump( 'after: ', $query, $params );
         $statement = $this->prepare($query);
         return $this->execute($statement, $params);
     }
 }
开发者ID:Garrett-Sens,项目名称:portfolio,代码行数:51,代码来源:mysql.php

示例2: init

	public function init()
	{	
		parent::init();

		$this->current_index = 0;
		
		// make sure $field was specified
		if (!$this->field)
			throw new Exception("field must be specified in resultfilter control");
		$this->filter_definition = $this->controller->appmeta->filter->{$this->field};
		
		if (!$this->datasource) /* Default to the datasource definition in the config file */
			$this->datasource = $this->filter_definition->datasource;
		$filter_type = $this->filter_definition->type;

		// Set container and item templates from config file if not passed into tag
		if (!$this->item_template)
			$this->item_template = $this->controller->appmeta->renderer_map->{$filter_type}->item;
			
		if (!$this->container_template)
			$this->container_template = $this->controller->appmeta->renderer_map->{$filter_type}->container;
				
		// dig specific facet counts out of facets
		if (is_assoc($this->datasource))
		{
			$facet = $this->datasource[$this->filter_definition->facet->field];
			$this->datasource = array();
			foreach($facet as $value => $count)
				$this->datasource[] = array('value' => $value, 'count' => $count); 
		}
	}
开发者ID:nikels,项目名称:HeavyMetal,代码行数:31,代码来源:resultfilter.php

示例3: testIsAssoc

 public function testIsAssoc()
 {
     $arr = ['a' => 0, 'b' => 1];
     $this->assertTrue(is_assoc($arr));
     $arr = ['a', 'b', 'c'];
     $this->assertFalse(is_assoc($arr));
 }
开发者ID:a11enwong,项目名称:pochika,代码行数:7,代码来源:HelpersTest.php

示例4: recursive

 function recursive($array, $level = 1)
 {
     $cur = 1;
     foreach ($array as $key => $value) {
         //If $value is an array.
         if (is_array($value)) {
             if (!is_numeric($key)) {
                 echo '"' . $key . '": ';
             }
             if (is_assoc($value)) {
                 echo '{ ';
             } else {
                 echo '[ ';
             }
             //We need to loop through it.
             recursive($value, $level + 1);
             if (is_assoc($value)) {
                 echo ' }';
             } else {
                 echo ' ]';
             }
         } else {
             //It is not an array, so print it out.
             echo '"' . $key . '": "' . $value, '"';
         }
         if ($cur != count($array)) {
             echo ', ';
         }
         $cur++;
     }
 }
开发者ID:baltedewit,项目名称:slogo-playout-server,代码行数:31,代码来源:api.php

示例5: __construct

 /**
  * __construct method
  * @param array $array
  * @array array $args
  * */
 public function __construct($array, $args)
 {
     $this->array = $array;
     $this->args = $args;
     is_assoc($this->array) ? $this->assocArray() : $this->sequentArray();
     $this->setRouting(implode('/', $this->array) . '/' . $this->args);
 }
开发者ID:varyan,项目名称:namecpaseSystem,代码行数:12,代码来源:RoutArray.php

示例6: array_str

function array_str($arr, $var_export_all = false)
{
    $is_assoc = is_assoc($arr);
    $result = '[';
    foreach ($arr as $key => $value) {
        if ($is_assoc) {
            $result .= $key . '=';
        }
        if (is_array($value)) {
            $result .= array_str($value);
        } else {
            if ($var_export_all) {
                $result .= var_export($value, true);
            } else {
                if (is_bool($value)) {
                    $result .= bool_str($value);
                } else {
                    if (is_string($value)) {
                        $result .= '"' . $value . '"';
                    } else {
                        if (is_string_convertable($value)) {
                            $result .= $value;
                        } else {
                            $result .= var_export($value, true);
                        }
                    }
                }
            }
        }
        $result .= ', ';
    }
    return remove_last($result, ', ') . ']';
}
开发者ID:matthew0x40,项目名称:apply,代码行数:33,代码来源:functions.php

示例7: __construct

 /**
  * Constructor
  *
  * @param array  $array     multidimensional associative array
  * @param string $separator [optional] default '.'
  *
  * @throws NonAssocException
  */
 public function __construct(array $array, $separator = '.')
 {
     if (!is_assoc($array)) {
         throw new NonAssocException();
     }
     $this->storage = $array;
     $this->separator = $separator;
 }
开发者ID:acim,项目名称:stdlib,代码行数:16,代码来源:DotArray.php

示例8: _refresh

 /**
  * @return $this
  */
 public function _refresh()
 {
     if (!is_assoc($this->_result)) {
         return $this;
     }
     DB::_getInstance()->query("UPDATE `Token` SET `Created` = NULL WHERE `ID` = {$this->_result['ID']};");
     return $this;
 }
开发者ID:enderteszla,项目名称:phpframework-etc,代码行数:11,代码来源:Token.php

示例9: copyKeys

 /**
  * Copy nodes
  *
  * @param array $keys associative array
  *
  * @throws NonAssocException
  *
  * @return $this
  */
 public function copyKeys(array $keys)
 {
     if (!is_assoc($keys)) {
         throw new NonAssocException();
     }
     foreach ($keys as $existingKey => $newKey) {
         $this->array->offsetSet($newKey, $this->array->offsetGet($existingKey));
     }
     return $this;
 }
开发者ID:acim,项目名称:stdlib,代码行数:19,代码来源:ArrayModifier.php

示例10: parseMatch

function parseMatch($match, $MAJOR_ITEMS)
{
    //Strip fields from participants
    // $support_1;
    // $support_2;
    $counter = 0;
    foreach ($match['participants'] as $participant) {
        // if ($participant['timeline']['role'] == 'DUO_SUPPORT' && $participant['teamId'] == 100)
        // 	$support_1 = $participant['participantId'];
        // if ($participant['timeline']['role'] == 'DUO_SUPPORT' && $participant['teamId'] == 200)
        // 	$support_2 = $participant['participantId'];
        unset($match['participants'][$counter]['masteries']);
        unset($match['participants'][$counter]['runes']);
        foreach ($participant['stats'] as $key => $value) {
            if ($key != 'deaths' && $key != 'kills' && $key != 'assists' && $key != 'winner') {
                unset($match['participants'][$counter]['stats'][$key]);
            }
        }
        $counter++;
    }
    unset($match['participantIdentities']);
    unset($match['teams']);
    //Strip events
    $frame_counter = 0;
    if (is_assoc($match['timeline']['frames'])) {
        return $match;
        //don't change doc at all
    }
    foreach ($match['timeline']['frames'] as $frame) {
        unset($match['timeline']['frames'][$frame_counter]['participantFrames']);
        if (isset($frame['events'])) {
            $counter = 0;
            foreach ($frame['events'] as $event) {
                if ($event['eventType'] != 'ITEM_PURCHASED') {
                    unset($match['timeline']['frames'][$frame_counter]['events'][$counter]);
                } else {
                    // if ($event['participantId'] != $support_1 && $event['participantId'] != $support_2 && !in_array($event['itemId'], $MAJOR_ITEMS['items']))
                    if (!in_array($event['itemId'], $MAJOR_ITEMS['items'])) {
                        unset($match['timeline']['frames'][$frame_counter]['events'][$counter]);
                    }
                    //remove event if not a major purchase by non-support
                }
                $counter++;
            }
            if (count($match['timeline']['frames'][$frame_counter]['events']) == 0) {
                unset($match['timeline']['frames'][$frame_counter]);
            }
        }
        $frame_counter++;
    }
    return $match;
}
开发者ID:AndrewAday,项目名称:Riot-API-Challenge-2.0,代码行数:52,代码来源:parse_match.php

示例11: replace

 public static function replace($subject, $variables)
 {
     if (is_array($variables) && is_assoc($variables)) {
         foreach ($variables as $key => $value) {
             $key = str_replace("[", "\\[", $key);
             $key = str_replace("]", "\\]", $key);
             $subject = preg_replace("/\\{\\{{$key}\\}\\}/", $value, $subject);
         }
         /* Remove any variables remaining */
         $subject = preg_replace("/\\{\\{[^}]*\\}\\}/", "", $subject);
     }
     return $subject;
 }
开发者ID:mbruton,项目名称:email_templates,代码行数:13,代码来源:model_email_template.php

示例12: setProperties

 public function setProperties($properties)
 {
     if (!is_array($properties)) {
         $properties = func_get_args();
     } elseif (is_assoc($properties)) {
         foreach ($properties as $key => $value) {
             $this->settable_properties[$key] = $value;
         }
         return;
     }
     foreach ($properties as $property) {
         $this->settable_properties[$property] = "";
     }
 }
开发者ID:BackupTheBerlios,项目名称:anemone,代码行数:14,代码来源:SettingsStore.php

示例13: is_red

function is_red($ob)
{
    if (!is_array($ob)) {
        return false;
    }
    if (!is_assoc($ob)) {
        return false;
    }
    foreach ($ob as $val) {
        if ($val === 'red') {
            return true;
        }
    }
    return false;
}
开发者ID:JimMackin,项目名称:AdventOfCode,代码行数:15,代码来源:day12-2.php

示例14: recursive_add

function recursive_add($obj)
{
    $total = 0;
    foreach ($obj as $k => $v) {
        if (is_scalar($v)) {
            $total += $v;
            if ($v === "red" && is_assoc($obj)) {
                // part 2
                return 0;
            }
        } else {
            $total += recursive_add($obj[$k]);
        }
    }
    return $total;
}
开发者ID:altef,项目名称:AdventOfCode,代码行数:16,代码来源:Day12.php

示例15: parse

 public function parse()
 {
     if (!$this->map) {
         throw new CSVParserException('$map must be defined.');
     }
     if (!is_assoc($this->map)) {
         throw new CSVParserException('$map must be associative.');
     }
     if (!$this->delimiter) {
         throw new CSVParserException('$delimiter must be defined.');
     }
     if (!$this->path) {
         throw new CSVParserException('$path must be defined.');
     }
     $csv = $this->remote ? $this->_getRemoteCSV() : $this->_getLocalCSV();
     return $csv;
 }
开发者ID:hshoghi,项目名称:cms,代码行数:17,代码来源:class.CSVParser.php


注:本文中的is_assoc函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。