Oihana PHP Arango

extractVertexIDs.php

Table of Contents

Functions

extractVertexIDs()  : array<string|int, mixed>
Extract unique vertex IDs from a list of edge documents.

Functions

extractVertexIDs()

Extract unique vertex IDs from a list of edge documents.

extractVertexIDs(array<string|int, mixed> $edges, string $side) : array<string|int, mixed>

This helper function is used to extract either the "_from" or "_to" vertex IDs from an array of edge documents (objects or arrays) and return only the unique IDs.

Parameters
$edges : array<string|int, mixed>

Array of edge objects or associative arrays containing _from and _to.

$side : string

The side to extract, either Schema::_FROM or Schema::_TO.

Tags
example
use oihana\arango\models\helpers\extractVertexIds;
use org\schema\constants\Schema;

$edges =
[
    (object) ['_from' => 'apis/1', '_to' => 'permissions/1'],
    (object) ['_from' => 'apis/1', '_to' => 'permissions/2'],
    ['_from' => 'apis/2', '_to' => 'permissions/1'],
];

$toIds = extractVertexIds($edges, Schema::_TO);
// Result: ['permissions/1', 'permissions/2']

$fromIds = extractVertexIds($edges, Schema::_FROM);
// Result: ['apis/1', 'apis/2']
author

Marc Alcaraz (eKameleon)

version
1.0.0
Return values
array<string|int, mixed>

Unique list of vertex IDs.

On this page

Search results