PHP.mk документација

CollectionModify::arrayInsert

Почист и полокален преглед на PHP референцата, со задржана структура од PHP.net и подобра читливост за примери, секции и белешки.

mysql-xdevapi-collectionmodify.arrayinsert.php PHP.net прокси Преводот се освежува
Оригинал на PHP.net
Патека mysql-xdevapi-collectionmodify.arrayinsert.php Локална патека за оваа страница.
Извор php.net/manual/en Оригиналниот HTML се реупотребува и локално се стилизира.
Режим Прокси + превод во позадина Кодовите, табелите и белешките остануваат читливи во истиот тек.
CollectionModify::arrayInsert

Референца за `mysql-xdevapi-collectionmodify.arrayinsert.php` со подобрена типографија и навигација.

mysql-xdevapi-collectionmodify.arrayinsert.php

CollectionModify::arrayInsert

(Нема достапни информации за верзијата, можеби е само во Git)

CollectionModify::arrayInsertInsert element into an array field

= NULL

public mysql_xdevapi\CollectionModify::arrayInsert(string $collection_field, string $expression_or_literal): mysql_xdevapi\CollectionModify

Adds an element to a document's field, as multiple elements of a field are represented as an array. Unlike mysql_xdevapi\CollectionModify::arrayAppend() this method allows to specify where the new element is inserted by defining which item it is after, whereas mysql_xdevapi\CollectionModify::arrayAppend() always appends the new element at the end of the array.

Параметри

collection_field

Identifies the item in the array after which the new element will be inserted. The format of this parameter is FIELD_NAME[ INDEX ] where FIELD_NAME is the name of the document field to add the element to, and INDEX is the INDEX of the element within the field.

The INDEX field is zero based, so the first item of the array has an index of 0.

expression_or_literal

The new element to insert after FIELD_NAME[ INDEX ]

Вратени вредности

A CollectionModify object that can be used to execute the command, or to add additional operations

Примери

Пример #1 mysql_xdevapi\CollectionModify::arrayInsert() example

<?php
$session
= mysql_xdevapi\getSession("mysqlx://user:password@localhost");
$session->sql("DROP DATABASE IF EXISTS addressbook")->execute();
$session->sql("CREATE DATABASE addressbook")->execute();

$schema = $session->getSchema("addressbook");
$collection = $schema->createCollection("people");

$result = $collection
->add(
'{"name": "Bernie",
"traits": ["Friend", "Brother", "Human"]}'
)
->
execute();

$collection
->modify("name in ('Bernie', 'Jane')")
->
arrayInsert('traits[1]', 'Happy')
->
execute();

$result = $collection
->find()
->
execute();

print_r($result->fetchAll());
?>

Горниот пример ќе прикаже нешто слично на:

Array
(
    [0] => Array
        (
            [_id] => 00005b6b5361000000000000010d
            [name] => Bernie
            [traits] => Array
                (
                    [0] => Friend
                    [1] => Happy
                    [2] => Brother
                    [3] => Human
                )
        )
)

Белешки од корисници

Нема белешки од корисници за оваа страница.
На оваа страница

Автоматски outline од активната документација.

Насловите ќе се појават тука по вчитување.

Попрегледно читање

Примерите, changelog табелите и user notes се визуелно издвоени за да не се губат во долгата содржина.

Брз совет Користи го outline-от Скокни директно на главните секции од активната страница.
Извор Оригиналниот линк останува достапен Кога ти треба целосен upstream context, отвори го PHP.net во нов tab.